jQuery selectors troubles

2019-08-04 05:03发布

I need help to understand why these things behave strange:

alert($('div.entry').text());                   returns some long text
alert(Thesaurus.options.containers);            returns string div.entry
alert($(Thesaurus.options.containers).text());  breaks with Uncaught RangeError: Maximum call stack size exceeded

The HTML has under 500 words in few div.entry elements.

The Thesaurus.options.containers looks like this:

jQuery.Thesaurus({
        caseSentitive: false,
        zetind: 'auto',
        delay: 250, 
        containers: ['div.entry'],
        effect: 'slide',
...

1条回答
来,给爷笑一个
2楼-- · 2019-08-04 05:31

So, basically, you're doing this: $(['div.entry]).text(); I'm guessing since you're passing an array that you're calling this: http://api.jquery.com/jQuery/#jQuery-elementArray which is meant to take an array of elements, not an array of selectors. You can see this blow up here: http://jsfiddle.net/dE9Yb/.

What you could do instead is this:

alert($(Thesaurus.options.containers.join(",")).text());

So, pass in one string that is a selector joined by commas.

See: http://jsfiddle.net/dE9Yb/1/

查看更多
登录 后发表回答