我是java脚本和HTML开发的新手。我需要将变量传递给$('td:nth(int))
。我尝试了这段代码,但它不起作用。
var index=2;
alert($('td:nth(index)').html);
答案 0 :(得分:1)
您可以使用简单的字符串连接来完成此操作。但是你的代码中存在一些错误:
:nth()
这样的伪类选择器,您可以使用 :nth-child()
或 :eq()
伪类选择器或html
属性,而是undefined
,而是使用 html()
方法。 var index=2;
alert($('td:nth-child(' + index + ')').html());