简体   繁体   English

在主页面中动态加载CSS和JS文件

[英]Dynamically loading CSS and JS files in main Page

i have some js and css files now my requirement to keep these link in xml files and apply on aspx page when page get load can anybody please help to do this 我现在有一些js和css文件,我的要求是将这些链接保留在xml文件中,并在页面加载时应用于aspx页面,任何人都可以帮助执行此操作

css Links : CSS链接:

<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/grid.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" />
<link rel="stylesheet" href="ed/bootstrap/css/bootstrap.css">

js links : js链接:

<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<script type="text/javascript" src="js/jquery.stellar.min.js"></script>
<script type="text/javascript" src="js/waypoints.min.js"></script>

xml File: i am not suer the way of writing xml file is correct or not xml文件:我不接受写xml文件的方法正确与否

<editor>
<template1>
<theme id="1" name="default">
<css><link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/grid.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" />
<link rel="stylesheet" href="ed/bootstrap/css/bootstrap.css"/>
</css>
<js>
  <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
  <script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
  <script type="text/javascript" src="js/js.js"></script>
  <script type="text/javascript" src="js/jquery.stellar.min.js"></script>
  <script type="text/javascript" src="js/waypoints.min.js"></script>
</js>
</theme>
</template1>
</editor>

I'm assuming you want the browser to dynamically load these files after being passed the XML file? 我假设您希望浏览器在传递XML文件后动态加载这些文件?

If so then use a combination of ajax to load the xml file, then something like Modernizr.load to load the files. 如果是这样,请结合使用ajax来加载xml文件,然后使用Modernizr.load之类的文件来加载文件。

http://modernizr.com/docs/#load http://modernizr.com/docs/#load

If the xml file is used on the server-side I guess just print the various links and scripts into your header before it's sent to the browser. 如果在服务器端使用xml文件,我猜只是在将各种链接和脚本打印到您的标头中,然后再发送到浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM