未捕获的语法错误,无法识别的表达式:[object Object] [英] Uncaught Syntax error, unrecognized expression: [object Object]

查看:165
本文介绍了未捕获的语法错误,无法识别的表达式:[object Object]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在新闻滚动条上工作 - 请参阅我的实例 - 示例

Working currenly on news scroller - see my live example here - EXAMPLE

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

When I press next/prev arrow I'm getting an error log Uncaught Syntax error, unrecognized expression: [object Object]

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

Why is the problem? Where is the error in the syntax?

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();

    });


推荐答案

要从现有对象构建选择器,请使用 $ 的第二个参数:

To build selectors from existing objects, use the second parameter of $:

$('div:visible', CurrentScrollerDiv)

查找功能

CurrentScrollerDiv.find('div:visible');

CurrentScrollerDiv 不是字符串所以它不能与字符串连接以生成基于字符串的选择器参数。

CurrentScrollerDiv is not a string so it cannot be concatenated with a string to generate a string-based selector argument.


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 )


这篇关于未捕获的语法错误,无法识别的表达式:[object Object]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆