gpt4 book ai didi

jquery - 未捕获语法错误,无法识别的表达式 : [object Object]

转载 作者:行者123 更新时间:2023-12-03 22:54:43 25 4
gpt4 key购买 nike

目前正在研究新闻滚动 - 请参阅我的实例 - EXAMPLE

当我按下一个/上一个箭头时,我收到错误日志未捕获的语法错误,无法识别的表达式:[object Object]

为什么会出现这个问题?语法错误在哪里?

jQuery 代码:

        (function($) {
/*! Scroller
---------------------------------------------*/
$.fn.Scroller = function() {

//Set height
$('.scroller').each(function() {
var height = 0;
$(this).children('div').each(function() {

if (height < $(this).height()) {
height = $(this).height();
}

});
$(this).css("height", height + "px");

});

$('.scroller').each(function() {

var NextArrow = $(this).parent().find('.next');
var PrevArrow = $(this).parent().find('.prev');


// Set a timeout
var timeOut = setTimeout(nextNotice, 5000);

// pause on hover
$(this).hover(

function() {
clearTimeout(timeOut);
}, function() {
timeOut = setTimeout(nextNotice, 5000);
});

// Next notice function called on timeout or click
//set a flag that use to be an oberver to listen when the fadeIn done
var flag = true;

function nextNotice(event) {

var CurrentScrollerDiv = $(this).parent().find('.scroller');

if (!flag) {
return false;
}
clearTimeout(timeOut);

flag = false;
timeOut = setTimeout(nextNotice, 5000);

if ($(CurrentScrollerDiv + ' div:visible').is(CurrentScrollerDiv + ' div:last-child')) {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300);
$(CurrentScrollerDiv + ' div:first-child').fadeIn("slow", function() {
flag = true;
});
} else {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300).next('div').fadeIn("slow", function() {
flag = true;
});
}
return false;
}

$(NextArrow).click(nextNotice);
$(PrevArrow).click(function(event) {

var CurrentScrollerDiv = $(this).parent().find('.scroller');

if (flag) {
return false;
}
clearTimeout(timeOut);

flag = false;
timeOut = setTimeout(nextNotice, 5000);

if ($(CurrentScrollerDiv + ' div:visible').is(CurrentScrollerDiv + ' div:first-child')) {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300);
$(CurrentScrollerDiv + ' div:last-child').fadeIn("slow", function() {
flag = true;
});
}
else {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300).prev('div').fadeIn("slow", function() {
flag = true;
});
}
return false;

});

});

};

})(jQuery);


$(document).ready(function() {
//Blog
$('.itBlog > div:first-child').show();

//Scroller
$('.scroller').Scroller();

});

最佳答案

要从现有对象构建选择器,请使用 the second parameter of $ :

$('div:visible', CurrentScrollerDiv)

或者the find function :

CurrentScrollerDiv.find('div:visible');

CurrentScrollerDiv 不是字符串,因此无法将其与字符串连接来生成基于字符串的选择器参数。

<小时/>
jQuery( selector, [ context ]  )
jQuery( selector, [context] ) <-- you want this one, and
jQuery( element ) `selector` is a string
jQuery( elementArray )
jQuery( jQuery object )
jQuery()
jQuery( html, [ ownerDocument ] )
jQuery( html, [ownerDocument] )
jQuery( html,props )
jQuery( callback )
jQuery( callback )

关于jquery - 未捕获语法错误,无法识别的表达式 : [object Object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7469925/

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