jQuery选择器的麻烦 [英] jQuery selectors troubles

查看:88
本文介绍了jQuery选择器的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来理解为什么这些事情表现得很奇怪:

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

HTML的div.entry元素少于500个字.

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

Thesaurus.options.containers看起来像这样:

The Thesaurus.options.containers looks like this:

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

推荐答案

因此,基本上,您正在执行以下操作:$(['div.entry]).text();我猜是因为您要传递的数组称为: href ="http://api.jquery.com/jQuery/#jQuery-elementArray" rel ="nofollow"> http://api.jquery.com/jQuery/#jQuery-elementArray 接受一个 elements 数组,而不是一个选择器数组.您可以在这里看到爆炸: http://jsfiddle.net/dE9Yb/.

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/.

相反,您可以做的是:

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

因此,传入一个字符串,该字符串是用逗号连接的选择器.

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

请参阅: http://jsfiddle.net/dE9Yb/1/

这篇关于jQuery选择器的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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