[英]Javascript Parent-Child items
I have a table with rows that looks like this 我有一张桌子,上面有这样的行
<tr>
<td>xyz</td>
<td>xyz</td>
<td>xyz</td>
<td><span class="label-success">Active</span></td>
<td><a href="#" onclick(my-js-here.js)>change status</a></td>
</tr>
<tr>
<td>xyz</td>
<td>xyz</td>
<td>xyz</td>
<td><span class="label-pending">Active</span></td>
<td><a href="#" onclick(my-js-here.js)>another change status</a></td>
</tr>
When I click the "change status" link, I want to be able to change the class "lable-success" to "label-fail" 当我单击“更改状态”链接时,我希望能够将类“标签成功”更改为“标签失败”
in my-js-here.js, how do I reference/pick out this in the in this same row 在my-js-here.js中,如何在同一行中引用/挑选
$(this).parents("tr:first").(this is where I am lost).removeClass('lable-success');
$(this).parents("tr:first").(this is where I am lost).addClass('fail');
Use: 采用:
$(this).parent().prev().find('span').toggleClass('label-success fail');
This will allow you to toggle the classes. 这将允许您切换类。 If you just want to be able to make the change once, change
.find('span')
to .find('.label-success')
如果您只想进行一次更改,
.find('span')
更改为.find('.label-success')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.