简体   繁体   English

在asp.net页面中使用jQuery时如何解决冲突

[英]How to solve conflict in jQuery when used in asp.net page

Below is the references and script I am using in the same page for date time picker and colour box. 以下是我在同一页面中用于日期时间选择器和颜色框的参考和脚本。 Only either one of them works when commenting the other script referenced. 评论另一个引用的脚本时,只有其中一个起作用。 I thought it may be due to conflict to used jQuery noconflict. 我认为这可能是由于使用jQuery noconflict引起的冲突。 But this didn't help. 但这没有帮助。

How can this be solved ? 如何解决呢?

        <%--DATE AND TIME PICKER--%> 
       <%-- <link rel="stylesheet" href="../Uploadedfiles/System/Scripts/jquery-ui.css" />
        <script src="Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
        <script src="Scripts/jquery-ui.min.js" type="text/javascript"></script> 
        <script src="Scripts/jquery-ui-timepicker-addon.js" type="text/javascript"></script>
        <script src="Scripts/jquery-ui-sliderAccess.js" type="text/javascript"></script>--%>

        <%--COLOR BOX--%> 
        <link rel="stylesheet" type="text/css" href="css/colorbox/colorbox.css" media="screen, projection" />
        <script type="text/javascript" src="js/jquery.colorbox-min.js"></script>
        <script src="js/jquery.colorbox.js" type="text/javascript"></script>


<script type="text/javascript"> 
        jQuery(document).ready(function ($) {
            $("[id*=txtfromdate]").datepicker();
            $("[id*=txttodate]").datepicker();
            $("[id*=txtClosingDate]").datepicker();

            $("[id*=txtTimestart]").timepicker({
                timeFormat: "hh:mm tt"
            });

            $("[id*=txtTimeend]").timepicker({
                timeFormat: "hh:mm tt"
            }); 
        });

</script>


<script type="text/javascript">
        function colorbox() {
            var hv = $("[id*=txt_Messsage]").val();
            $.colorbox({ width: "50%", height: "30%", html: hv })
            alert(hv);
        }
</script> 

Yes, As you have suspected correctly, it might be the situation that some of the functions might be present in two of your JQuery files that might have been creating that conflict. 是的,正如您正确怀疑的那样,可能是某些功能可能出现在您的两个JQuery文件中,这些文件可能一直在造成这种冲突。

Solutions: 1) Try to identify which of the function is common between your jQuery files Or else Try to use a single jQuery file and copy the additional functions that you need to one of the jQuery files. 解决方案:1)尝试确定您的jQuery文件之间共有哪些功能,或者尝试使用单个jQuery文件并将所需的其他功能复制到其中一个jQuery文件中。 2) else use jQuery.noConflict(); 2)否则使用jQuery.noConflict(); inside

this jQuery(document).ready(function ($) { 这个jQuery(document).ready(function ($) {

Cheers!!!! 干杯!!!!

Use $.noConflict(); 使用$.noConflict(); before the code that might create conflict 在可能造成冲突的代码之前

Refer this link 引用此链接

As an addition to others answers , 除了其他答案之外,

Once you do : $.noConflict(); 完成后: $.noConflict(); you are back to jQuery ( and not to the dollar sign) 您又回到了jQuery (而不是美元符号)

But you can also do : 但是您也可以:

var _=$.noConflict(); 

And now you can use _("#myId")... 现在您可以使用_("#myId")...

NB you might need the overload : 注意,您可能需要重载:

jQuery.noConflict( [removeAll ] )

A Boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself). 一个布尔值,指示是否从全局范围(包括jQuery本身)中删除所有jQuery变量。

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

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