Linux 在页面中多次引用 JQuery 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple References to the JQuery Library in a page
提问by Achilles
I have an ASP.NET application using a master page. I am adding a reference to the JQuery library in the master page however there are some content pages and user controls that reference the JQuery library directly. Will I need to remove each reference from those pages or can I leave them in place even though I am adding a reference into the master page of the application?
我有一个使用母版页的 ASP.NET 应用程序。我在母版页中添加了对 JQuery 库的引用,但是有一些内容页面和用户控件直接引用了 JQuery 库。 我是否需要从这些页面中删除每个引用,或者即使我在应用程序的母版页中添加了引用,也可以将它们保留在原处?
采纳答案by Armstrongest
If you're loading jQuery with the Script Manager, it should load only once.
如果您使用脚本管理器加载 jQuery,它应该只加载一次。
If you still want intellisense, you can use the following trick:
如果你仍然想要智能感知,你可以使用以下技巧:
<% if (false) { %>
<script src="....... script tag here
<% } %>
回答by Nick Craver
You should remove them, including the library twice has many side-effects, wiping out any plugins defined for example. It'll load fine, but you'll start getting .pluginMethod
is not defined, etc.
你应该删除它们,包括库两次有很多副作用,例如删除任何定义的插件。它会加载得很好,但你会开始得到.pluginMethod
未定义等。
To avoid the headaches, only include them once, or register the scriptwith the same key, and let ASP.Net do the include, and with the same key, it'll do so only once.
为了避免麻烦,只包含一次,或者使用相同的密钥注册脚本,让 ASP.Net 进行包含,使用相同的密钥,它只会这样做一次。
回答by Roger Walsh
You will need to remove them I'm afraid. Came across this issue myself and the javascript will break.
恐怕您需要将它们移除。我自己遇到了这个问题,javascript 会崩溃。