【发布时间】:2014-04-23 05:16:09
【问题描述】:
我在我的应用程序的 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 页面中使用它。如何在所有页面中避免这种情况?请帮忙
【问题讨论】:
-
如果about.html是用jquery加载的,为什么还要在about.html中再次包含jquery?
-
当我打开我的masterpage.html时,我会点击一个关于的链接,它完美地加载了一个页面。但是当我在 about.html 中编写诸如 alert($("#username").val()) 之类的 jquery 函数时遇到问题,它将显示错误 $ 未定义。然后它强制在我的 about.html 中包含 jquery cdn
-
您能否显示您尝试执行此操作失败的代码,即不包括 jquery 的 about.html,以及包含该警报的
-
Uncaught ReferenceError: $ is not defined comaccesscards:60 Uncaught ReferenceError: jQuery is not defined comaccesscards:112 Uncaught ReferenceError: jQuery is not defined
标签: java javascript jquery jquery-ui