0

我正在尝试使用gt()jQuery 集的过滤器。我的愿望是清除所有索引高于触发更改事件的元素的选定元素。我确定这与无法gt()将变量作为整数接受有关thisIndex,并且似乎找不到这样做的语法。

$(document).ready(function () {  
    $(".slct").change(function() { // sensitize all slct elements  
        thisIndex = $(".slct").index(this);  
        selGT1 = $(".slct:gt(1)"); // TEST: this correctly selects the elements greater than 1    
        selectsGT = $(".slct:gt(thisIndex)"); // "I WANT thisIndex TO ACT LIKE A INTEGER"    
        $(selectsGT).val(""); // clear elements w/ a index greater than "this"  
    });  
});
4

1 回答 1

2

目前在您的代码中,“thisIndex”被解释为字符串的一部分。您需要将整数与字符串连接起来。所以下面的代码片段应该可以解决问题:

selectsGT = $(".slct:gt(" + thisIndex + ")");
于 2013-02-13T17:30:02.990 回答