admin管理员组文章数量:1291010
I am not too familiar with jQuery.noConflict
. I have tried to implement it a couple times, but I feel I am doing it wrong.
Is there a way to set a noConflict with "jquery-1.7.1.min.js"? Do I put it in the actual file, or in the header of my index or both? I have tried to follow examples but I know I am doing it wrong.
Any guidance or quick examples would help me tremendously!
I am not too familiar with jQuery.noConflict
. I have tried to implement it a couple times, but I feel I am doing it wrong.
Is there a way to set a noConflict with "jquery-1.7.1.min.js"? Do I put it in the actual file, or in the header of my index or both? I have tried to follow examples but I know I am doing it wrong.
Any guidance or quick examples would help me tremendously!
Share Improve this question edited Apr 25, 2012 at 17:44 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Apr 25, 2012 at 17:42 MichaelMichael 1232 silver badges8 bronze badges 1- How to help you when we can't even see how you're doing it or what you may be doing wrong? – Sparky Commented Apr 25, 2012 at 18:03
4 Answers
Reset to default 4var foo = $.noconflict();
foo('body').addClass('bar');
You can either assign it a new alias (as shown above) or call $.noConflict
and only have jQuery
available for use. If you chose an alias though you must use that new alias every time you want to reference jQuery.
Keep in mind though that you can enable noConflict, but still have it available when necessary using an anonymous function:
// disable $ and force use of myJQ
var myJQ = jQuery.noConflict();
(function($){
//
// be able to use $ within this block and have it mean jQuery
//
$('body').addClass('foo');
})(myJQ);
// we're outside the block, now we're back to myJQ
myJQ('body').removeClass('foo');
No conflict mode is easy to use. Include this shortly after loading jQuery and any jQuery-dependent libraries:
var $j = jQuery.noConflict();
Then, instead of using $
for everything, use $j
:
var elements = $j('.class-name');
Have you tried the following examples:
http://api.jquery./jQuery.noConflict/
I think it says all about it. Check your browser console to see any errors.
I'd remend using a noConflict
call, as well as wrapping your jQuery code with an anonymous function, so you can call jQuery by $
:
jQuery.noConflict();
(function ($) {
// Now you can use $ to call jQuery
}(jQuery));
本文标签: javascriptJquery No Conflict jquery171minjsStack Overflow
版权声明:本文标题:javascript - Jquery No Conflict jquery-1.7.1.min.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741508262a2382449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论