jQuery multiple class and nth-child
jQuery multiple class and nth-child
我有一个有多个类的表。
<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>
<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>
<tr>
<td class='one two'>One</td>
<td class='one three'>Another</td>
<td class='one example'>Yet another</td>
<td class='one two'>Yet another</td>
<td class='four'>Four</td>
</tr>
我想要的是设置包含 td 的每个 tr 中的第一个文本具有类"一",如果添加另一个类,则没有马瑟。
我尝试过一个经典的例子,但它不起作用:
var i=0;
$(".one:nth-child(1)").each(function() {
temp[i] = $(this).text;
console.log("Result: "+temp[i]);
i++;
});
但这行不通。
您需要使用:
$("tr td.one:first-child").each(function(i) {
temp[i] = $(this).text();
console.log("Result: "+temp[i]);
});
工作演示
相关文章:
- Selenium WebDriver and JavaScript change
- PHP and Javascript functions
- Javascript Return and if/else
- SetTimeout and clearTimeout in Javascript
- lightbox in html 5 and javascript
- jQuery multiple class and nth-child
- 使用:nth-child()选择器和.get()方法之间的性能差异
- 将所有元素包装到 :nth-child
- jquery 如何使用 tr:nth-child(i) 构造每个或 for 循环构造
- JQuery to css write nth-child()
- jquery :nth-child() 类不工作
- jQuery - Object + nth-child
- :nth-child()对李添加的foreach数据绑定无效
- iOS8 Safari在pushState之后:nth-child()选择器不起作用
- ng-repeat and json for child pages not showing in li's
- jQuery select multiple :nth-child()
- j查询 :eq() 和 :nth-child() 之间的区别
- 选择Jquery中nth-child和nth-last-child之间的所有元素
- 为什么我的 :nth-child(2) 选择器在我的 jQuery 中不起作用
- jQuery nth-child nth-of-type Not Working