Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取jQuery筛选器以接受整数变量_Jquery_Variables_Filter - Fatal编程技术网

获取jQuery筛选器以接受整数变量

获取jQuery筛选器以接受整数变量,jquery,variables,filter,Jquery,Variables,Filter,我正在尝试使用jQuery集合的gt()过滤器。我希望清除索引高于触发更改事件的元素的所有选定元素。我确信这与无法获取gt()以接受变量thisIndex作为整数有关,而且似乎找不到这样做的语法 $(document).ready(function () { $(".slct").change(function() { // sensitize all slct elements thisIndex = $(".slct").index(this);

我正在尝试使用jQuery集合的
gt()
过滤器。我希望清除索引高于触发更改事件的元素的所有选定元素。我确信这与无法获取
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"  
    });  
});
当前在代码中,“thisIndex”被解释为字符串的一部分。您需要将整数与字符串连接起来。所以下面的代码片段应该可以做到这一点:

selectsGT = $(".slct:gt(" + thisIndex + ")");

jQuery选择器是一个字符串。您必须使用字符串加法来构建正确的字符串,以构造一个将数值作为字符串包含在其中的字符串。