简体   繁体   中英

jquery.min.js Conflicts

When I add the below script ,it effecting other functionality of the project(Spring Application)

  <script type="text/javascript" src="${ctx}/js/jquery-1.3.2.min.js"></script>

My Code

    <script type="text/javascript" src="${ctx}/js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/easy.notification.js"></script>
    <script type="text/javascript">

    $.noConflict();

    $(function() {
            $("input[type='text']").blur(function() {

                if (this.value === '') {
                    $.easyNotificationEmpty('Warning : You left this field empty !');
                } else {
                    $.easyNotification('Saved Successfully !');
                }
            })
        });
</script>

I suspect that it because of the conflict of jquery-1.3.2.min.js

I have tried $.noConflict(); , but am not getting desired results.

Please help me to resolve this problem, Thanks in advance.

Try this,

jQuery(function($) {
    $("input[type='text']").blur(function() {

        if (this.value === '') {
            $.easyNotificationEmpty('Warning : You left this field empty !');
        } else {
            $.easyNotification('Saved Successfully !');
        }
    })
});

Use $.noConflict(); before you include new jquery plugin like below,

//your old plugin here

<script type="text/javascript">

$.noConflict();

</script>

// new plugin here 

//new script here

Try implementing jQuery.noConflict on the alias you'll be using on the script that causes other scripts to break.

var someAlias = $.noConflict();

And use someAlias instead of $ on the script that causes the problem.

You could test that and see if this makes any difference:

(function ($) {
    $(function() {
            $("input[type='text']").blur(function() {

                if (this.value === '') {
                    $.easyNotificationEmpty('Warning : You left this field empty !');
                } else {
                    $.easyNotification('Saved Successfully !');
                }
            })
        });
})(jQuery.noConflict(true))

For example:

http://jsfiddle.net/6zXXJ/

I use with TRUE,... this work!:

//your old plugin here


<script type="text/javascript">

$.noConflict(true);

</script>

// new plugin here 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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