简体   繁体   English

从后面的代码引用一个jQuery库

[英]referencing a jquery library from code behind

Is there a way I can reference a jquery library from code behind , in the master page. 有没有一种方法可以从母版页后面的代码中引用jquery库。

This is because I only want to use jquery on aspx pages that need to use them. 这是因为我只想在需要使用jasp的aspx页面上使用jquery。 Currently I have my jquery reference in the form tag and it gets loaded on every page load. 目前,我在表单标签中有我的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>

If you just want to reference external JS file in content pages, you can use ScriptManagerProxy control. 如果只想在内容页面中引用外部JS文件,则可以使用ScriptManagerProxy控件。 It will act pretty much like ScriptManager, but won't confilct with ScriptManager of the Master Page 它的行为几乎类似于ScriptManager,但不会与母版页的ScriptManager冲突

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

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