在jquery中更改函数的选择器

时间:2014-08-26 09:00:39

标签: javascript jquery

我需要一些帮助。看看你是否可以帮助我。 我有一个函数,其形式是:

$this.find(settings.selector).each(function(index) {

无论如何,根据变量可以更改选择器如下:

$this.each(function(index) {
你能告诉我怎么做吗?我希望我已经大致解释过了。 谢谢。

1 个答案:

答案 0 :(得分:4)

您可以使用像

这样的临时变量
var $els;
if (some_condition) {
    $els = $this.find(settings.selector)
} else {
    $els = $this;
}
$els.each(function (index) {});