页面中对 JQuery 库的多次引用
我有一个使用母版页的 ASP.NET 应用程序。我在母版页中添加对 JQuery 库的引用,但是有一些内容页面和用户控件直接引用 JQuery 库。 我是否需要从这些页面中删除每个引用,或者即使我将引用添加到应用程序的母版页中,我也可以将它们保留在原处吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
恐怕你需要将它们删除。我自己也遇到过这个问题,javascript 会崩溃。
You will need to remove them I'm afraid. Came across this issue myself and the javascript will break.
您应该删除它们,包括两次库会产生很多副作用,例如清除定义的任何插件。它会加载得很好,但你会开始得到
.pluginMethod
is not Defined 等。为了避免麻烦,只包含它们一次,或者 使用相同的密钥注册脚本,并让 ASP.Net 进行包含,并且使用相同的密钥,它将只执行一次。
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.To avoid the headaches, only include them once, or register the script with the same key, and let ASP.Net do the include, and with the same key, it'll do so only once.
如果您使用脚本管理器加载 jQuery,它应该只加载一次。
如果你仍然想要智能感知,你可以使用以下技巧:
If you're loading jQuery with the Script Manager, it should load only once.
If you still want intellisense, you can use the following trick: