Jquery Load函数不引用母版页脚本文件

时间:2014-04-23 05:16:09

标签: java javascript jquery jquery-ui

我在我的应用程序 masterpage.html 中使用了jquery加载函数,它运行正常。但问题是我需要将Jquery.min.js放在我的所有内容页面中,以便在我的内容页面中使用jquery功能。我不想将它包含在所有页面中。它应该从我的母版页中引用。

<html>
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
<script type="text/javascript">

    function loadContent(pagename) 
    {
         $("#output").load(pagename);
    }
</script>

</head>
<body>
<a href="#" onclick="loadContent('about.html')">About</a>

<div id="output"></div>


</body>
</html>

about.html

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
<div id="content">
This is about page !!
 </div>

当你看到我的 about.html 时,再次使用jquery以便在我的about.html页面中使用它。如何在所有页面中避免这种情况?请帮忙

2 个答案:

答案 0 :(得分:0)

不,这是不可能的。您必须将它包含在使用jquery的所有页面中

而不是像下面那样引用网址,

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

您可以将jquery库下载到项目路径中并像

一样使用它
<script src="project_name/folder_name/jquery.min.js">

但必须在所有页面中包含jquery

希望这会有所帮助!!

答案 1 :(得分:0)

我无法给你最好的答案,这些是我的建议

  1. jQuery文件最好包含在 body 标记的底部。
  2. 如果您使用jQuery,则必须包含它。