2014-06-19 29 views
-6

我有这个jQuery表达与变量代替n而找到的第n个孩子的jQuery

var splitindex = 9; 
var mElems = $('#columns div:nth-child(n+9)'); 

在这里,“9”是硬编码, 如何使用splitindex替代9。 我想这样做的动态值为n;

+7

'$( '#列格:第n个孩子(N +' + splitindex + ')');' –

+1

'变种mElems = $('#列格:nth-​​child(n +'+ splitindex +')');' –

+1

这工作感谢Arun – Dwellerincellar

回答

0

这样:

$('#columns div:nth-child(n+'+splitindex +')') 
+1

你有没有注意到这部分..? 'nth-child(n'+ splitindex +')'仔细观看..! – Balachandran

0

试试这个

$("#columns div:nth-child(n+"+splitindex+")"); 
0

使用它,就像你追加一个字符串'string'+ val +'remaining'

var mElems = $('#columns div:nth-child(n+'+ splitindex +')'); 
0

使用此:

var mElems = $('#columns div:nth-child(n+'+splitindex +')'); 
0

你可以简单地做这样的:

var splitindex = 9; 
$("#columns div:nth-child(n+"+splitindex+")");