Jquery Index()返回-1

问题描述 投票:0回答:1

我有以下功能,其中html是在Javascript中创建的。在test(test1)我正在检查test1.Test__c是否为null并改变颜色。 .table-striped > tbody > tr.testcss“ - >正在改变行颜色。

但我得到了

var id=$( ".table-striped > tbody > tr.testcss" ).index() --> -1.

我得到的是在我的情况下,那时候因为索引返回-1而没有构建行。

谁能说出如何解决这个问题。

function ttttttt(test1) {
    var styleClass = "testcss";

    var html = '<tr class="' + styleClass + '" id="' + test1.Id +'">';
    return html + test(test1);
}


function test(test1) {
    var html = '<td class="cell col-md-2">' +'</td>';

    var opt = test.Test__c;
    if(oppchek === undefined){
        var id=$( ".table-striped > tbody > tr.testcss" ).index();
       );
        ++id;
    } else {
    }
    return html;
}
javascript jquery html indexing
1个回答
0
投票

在jsFiddle工作:https://jsfiddle.net/pranayamr/rkcxqyw9/3/

alert($('table > tbody > tr.testcss').index());

//if you want to work on all tr having `testcss` than do like this 
$('table > tbody > tr.testcss').each(function(){
       alert($(this).index());
})
© www.soinside.com 2019 - 2024. All rights reserved.