[英]java script error on moving the jquery references to the asp.net master page
我使用jquery,並且看到當前,在每個內容頁面中都為Jquery提供了引用。 我計划將所有引用移至母版頁,以便在需要時可以輕松進行更新。
因此,我從內容頁面刪除了jquery引用,並將它們放置在母版頁的頭部,如下所示:
<head id="Head1" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link href="App_Themes/masterStyleSheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css"
<asp:ContentPlaceHolder ID="ExtraHeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
當我運行應用程序時,出現以下錯誤:
JavaScript runtime error: 'jQuery' is undefined
從我的在線研究中,這是正確的方法..但是我得到了錯誤。 誰能幫助我,指出出什么問題或需要做什么?
將jquery腳本標簽移到jui ui腳本標簽上方,並刪除jui ui引用之一,因為您不需要兩次包含它們:
<head id="Head1" runat="server">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<link href="App_Themes/masterStyleSheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css"
<asp:ContentPlaceHolder ID="ExtraHeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
jQuery未定義,因為jui ui庫在jquery-1.9.1.js文件中定義之前嘗試使用jQuery引用。
首先,更改對jQuery UI和jQuery庫的調用順序,所有使用jQuery的庫或插件在調用前都需要定義jQuery,這適用於所有庫或框架:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
然后,以便您可以在代碼中看到兩次調用jQuery UI,請檢查此內容,以及是否兩次調用jQuery或其他庫:
http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js
http://code.jquery.com/ui/1.10.3/jquery-ui.js
您正在加載jQuery庫之前調用jQuery ui庫
您的代碼
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
更改為
首先調用jQuery庫文件
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.