jQuery 选择最近的跨度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6831264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:25:57 来源:igfitidea点击:
Select Closest span
提问by Reddy
Here is my HTML code
这是我的 HTML 代码
<span class="xxt" style="">Hide Me</span>
<div><br/></div>
<div></div>
<span style="">
<table>
<tr>
<td style="">
<div></div>
<input type="radio" class="a">
</td>
</tr>
</table>
</span>
<span class="xxt" style="">Hide Me</span>
<div><br/></div>
<div></div>
<span style="">
<table>
<tr>
<td style="">
<div></div>
<input type="radio" class="a">
</td>
</tr>
</table>
</span>
I am trying to access the closest span element with class "xxt" which is nearer to the parent span of the changed radio button.
Here is my code
我正在尝试使用类“xxt”访问最接近的跨度元素,该元素更接近更改后的单选按钮的父跨度。
这是我的代码
$('.a').live('change',function()
{
$(this).parents('span').closest('.xxt').addClass('DestQID');
$('.DestQID').hide();
});
Here is my test jsfiddle
回答by Igor Dymov
Try this:
尝试这个:
$('.a').live('change',function()
{
$(this).closest('span').prevAll('.xxt:first').addClass('DestQID');
$('.DestQID').hide();
});