我正在测试表中的一行是否是第一个子行。到目前为止我已经:
//the loop works
$('#GridFolderPopup').find('tr').each(function () {
if ( $(this).is(:first) == true ) //this is the faulty line
{
$(this).addClass('GridFolderRow');
};
});
有什么建议吗?
谢谢
最佳答案
尝试 .is(':first')
而不是 .is(:first)
。
您可能会将 Javascript 与 Ruby 混淆:在 Javascript 中,不能像这样使用冒号(在字符串之外)。
编辑
另外,在您的情况下 ':first-child'
选择器可能更合适。请参阅有关差异的文档
http://api.jquery.com/first-child-selector/
http://api.jquery.com/first-selector/
关于jquery - 测试是否是第一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5012639/