2013-09-30 133 views
0

由于特定的原因。我有我的jquery引用内的身体html标记而不是head html标记的表单标记。仅在某些aspx页面上动态加载jquery库

一切工作正常,直到这里,但由于我如何使用我的代码,每个 页(aspx页)加载jquery库。

我想仅在需要它们的页面上加载jquery引用。有没有办法我可以做到这一点?

这是我的母版页当前代码:

<body> 
    <form id="form2" runat="server"> 
    <asp:ScriptManager ID="ScriptManagerService" runat="server"> 
     <Scripts> 
      <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ScriptMode="Auto" /> 
      <asp:ScriptReference Path="http://code.jquery.com/jquery-migrate-1.2.1.js" ScriptMode="Auto" /> 
      <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" ScriptMode="Auto" /> 
     </Scripts> 
    </asp:ScriptManager> 
    </form> 
</body> 
+0

如果只有特定的页面需要jQuery,这意味着您要在这些页面上添加自定义客户端代码。在这种情况下,只需在自定义代码中加载jQuery引用,例如使用脚本标记。 – Christophe

回答

0

在母版中删除的ScriptReference到jQuery和具有参考jQuery的添加的ScriptManagerProxy到需要它们的网页:

<body> 
    <form id="form2" runat="server"> 
     <asp:ScriptManagerProxy ID="ScriptManagerService" runat="server"> 
      <Scripts> 
       <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ScriptMode="Auto" /> 
       <asp:ScriptReference Path="http://code.jquery.com/jquery-migrate-1.2.1.js" ScriptMode="Auto" /> 
       <asp:ScriptReference Path="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" ScriptMode="Auto" /> 
      </Scripts> 
     </asp:ScriptManagerProxy> 
    </form> 
</body>