如何处理两个版本的jQuery

时间:2013-08-08 06:06:35

标签: jquery asp.net asp.net-mvc-3 unobtrusive-validation

我在ASP.NET MVC 3项目中使用Twitter BootStrap。它使用 jquery-unobtrusive-validation.js 进行不显眼的验证,并在内部实现 .live()方法。需要使用小于1.7的jQuery文件才能生效,因为.live()从1.7版开始不推荐使用。

对于twitter Bootstrap, bootstrap.js 文件中实现了 .on()方法,其中需要jquery文件版本为1.7 +。

所以最后问题是,如果我添加 jquery-1.5.0.js ,bootstrap无法正常工作,当我添加 jquery-1.9.0.js ,不显眼的验证不起作用。我如何引用两个jQuery文件或如何摆脱这个问题?请帮忙。非常感谢。

1 个答案:

答案 0 :(得分:2)

打开“jquery.validate.unobtrusive.js”,更改最后一行:

}(jQuery));

}(oldJQuery ));

现在,您可以使用这样的旧插件:

   <script type="text/javascript" src="../../script/jquery-1.5.0.min.js"></script>
    <!-- store and protect the old one -->
    <script>
    var oldJQuery = jQuery.noConflict();
    </script>
    <script type="text/javascript" src="../../script/jquery.validate.unobtrusive.js"></script>

    <!-- load the new version and required plugins -->
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/bootstrap.js"></script>