我是 java 脚本和 HTML 开发的新手。我需要将变量传递给 $('td:nth(int))
。我尝试了这段代码,但它不起作用。
var index=2;
alert($('td:nth(index)').html);
最佳答案
您可以通过简单的字符串连接来完成。但是您的代码中存在一些错误:
- 没有像
:nth()
这样的伪类选择器,您可以使用:nth-child()
或:eq()
伪类选择器或 . - jQuery 对象没有
html
属性,它将是undefined
,而是使用html()
方法。
var index=2;
alert($('td:nth-child(' + index + ')').html());
关于javascript - 我需要将一个整数传递给 'td:nth',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38006137/