gpt4 book ai didi

javascript - jcarousel和jquery新添加的脚本冲突

转载 作者:行者123 更新时间:2023-11-28 08:37:58 24 4
gpt4 key购买 nike

下面的代码和另一个 jquery 代码有冲突。我修复了与已经使用的 ajax 选项卡的另一个冲突

 jQuery.noConflict();
jQuery(function ($) {
// jQuery code in here
});

但发现 jcarousel 触发了另一个冲突,执行相同操作并不能解决该问题,任何建议将不胜感激。

Jcarousel代码

    <script type="text/javascript" src="{$smarty.const._URL}/js/jquery.jcarousel.pack.js"></script>
{literal}
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
size: {/literal}{$total_playingnow}{literal}
});
});
</script>

触发冲突的新代码(facebook弹出likebox):

<script type="text/javascript"/>
jQuery.noConflict();
jQuery(function ($) {
//<![CDATA[
jQuery.cookie = function (key, value, options) {

// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);

if (value === null || value === undefined) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

value = String(value);

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
//]]>

jQuery(document).ready(function($){
if($.cookie('popup_user_login') != 'yes'){
$('#fanback').delay('3000').fadeIn('medium');
$('#fanclose, #fan-exit').click(function(){
$('#fanback').stop().fadeOut('medium');
});
}

});
});

最佳答案

jQuery(function ($) {
// jQuery code in here
});

可以改为

(function($){

//code here

})(jQuery)

这应该可以解决冲突问题。

关于javascript - jcarousel和jquery新添加的脚本冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20846625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com