如何避免jquery冲突? [英] How to avoid jquery conflict?

查看:83
本文介绍了如何避免jquery冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have one _Layout.cshtml which contains the below scripts

    <script src="~/Scripts/list.min.js"></script>        
    <script src="~/Scripts/moment.js"></script>
    <script src="~/Scripts/jquery.min.js"></script>

and another one child _PartialView.cshtml

if i include the above scripts in master layout the _PartialView.cshtml page functionality is working fine but remaining pages ajax functionalities are breaking because the bundle already has the jquery 7Version .min.js.

If i include   the below scritps 
    <script src="~/Scripts/list.min.js"></script>        
    <script src="~/Scripts/moment.js"></script>
    <script src="~/Scripts/jquery.min.js"></script>

remaining all pages functinalitis are working except _PartialView.cshtml.
Could you please suggest best solution to resolve this issue.





我的尝试:





What I have tried:

I have tried to put scripts in child page but not working 

推荐答案

将所需的所有脚本放在主布局中。避免在部分视图中添加脚本,但是如果你必须添加一个脚本,请确保只需要在该视图上,而不是其他任何地方。



请记住,当你的观点为布局在不同的物理文件中,浏览器将单个文件拼接在一起,因此如果您的部分视图需要jQuery,则如果它位于主布局中,则无需将它们包含在局部视图中。
Put all the scripts you need in the master layout. Avoid adding scripts to the partial view, but if you must add one make sure it is only needed on that view and nowhere else.

Remember that while your views\layouts are in different physical files, the browser sees a single file stitched together so if your partial views need jQuery there is no need to include them in the partial view if it is in the main layout.


这篇关于如何避免jquery冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆