jQuery突出显示无线电选择的表格行 [英] jQuery to highlight table row on radio select

查看:97
本文介绍了jQuery突出显示无线电选择的表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表(标准标记),每行都有一个无线电选择。一旦收音机被选中,我想强调一下。听起来很简单,但我无法触发它。



以下是标记:

表格行:


< tr>

< td>一些数据< / td> >
< td>一些资料< / td>

< td>一些资料< / td>

< td>

< label class =label_radio>< input type =radioname =amevalue =val/>< / label>

< / td> >
< / tr>



这是JS的相关部分:
(修饰用于将单选按钮进行类型化的标签,这个位不会):

  $('。label_radio input:checked')。each(function() {
$(this).parent('label')。addClass('r_on');
$(this).parent('tr')。addClass('。hilite'); //这一行不起作用
});

有什么想法?如果我没有提供足够的英特尔,请说,我会为你提供你所需要的。

提前非常感谢:)

解决方案

收音机的父母实际上并不是表格行,而是标签。使用 .closest 方法来查找父链,直到找到 TR

  $(this).closest('tr')。addClass('hilite'); 


I have a table (standard markup) with a radio select in each row. Once the radio is selected I'd like to highlight that . Sounds straight forward enough but I can't get it to trigger.

Here's the markup:

The Table Row:

<tr>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>
<label class="label_radio"><input type="radio" name="ame" value="val" /></label>
</td>
</tr>

This is the relevant part of the JS: (mods the label to sexify the radio button, that bit works, the bit doesn't):

$('.label_radio input:checked').each(function(){ 
$(this).parent('label').addClass('r_on');
$(this).parent('tr').addClass('.hilite'); //this line doesn't work
});

Any ideas? If I haven't given enough intel, please say and I'll get you what you need.

Greatly appreciated in advance :)

解决方案

The radio's parent isn't actually the table row, it's the label. use the .closest method instead to look up the parent chain until you get to the TR.

$(this).closest('tr').addClass('hilite');

这篇关于jQuery突出显示无线电选择的表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆