开发者

How to include variables in javascripts strings

开发者 https://www.devze.com 2023-04-12 13:26 出处:网络
I have the script as as follows: I want to inclde th index va开发者_如何学JAVAlue as shown below.How can I do that? With my actual code,I am having error

I have the script as as follows: I want to inclde th index va开发者_如何学JAVAlue as shown below. How can I do that? With my actual code,I am having error

for(var index = 1; index < 6; index++){

   $("#myTable thead td:nth-child(index + 2).html("here");

}


You could do:

for(var index = 1; index < 6; index++){
   var nthchild = index+2;
   $("#myTable thead td:nth-child("+nthchild+")").html(index);
}


You have to write:

for(var index = 1; index < 6; index++) {
    $("#myTable thead td:nth-child("+(index+2)+")").html("here");
}


Concatenate string, and sorted your syntax error:

  for(var index = 1; index < 6; index++)
  {    
      $("#myTable thead td:nth-child(" + (index+2) + ")").html('here');
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消