Jquery中的变量调用

Cov*_*ove -3 javascript jquery

我的问题非常简单,但我自己无法解决.所以,我有Jquery代码:

$( ".ms-listviewtable th:nth-child(1)" ).css("background-color", "#97002e");
Run Code Online (Sandbox Code Playgroud)

它工作得很完美,但是,而不是1我想使用变量,例如var abc=2,我想ab在我的代码中使用c而不是1.我怎么称呼它?

Chr*_*örz 5

在字符串中添加变量.

var yourVariable = 1;
$( ".ms-listviewtable th:nth-child("+yourVariable+")" ).css("background-color", "#97002e");
Run Code Online (Sandbox Code Playgroud)