jquery 兄弟姐妹属性到数组
任何人都知道如何将所有同级(单选按钮组的标签)的属性“rel”的值获取到数组中?
我已经尝试过类似的方法,但它显然不起作用:
<label rel="option_local" class="type_radio" for="type_3">
<input type="radio" checked="checked" value="3" id="type_3" name="type" />
Local</label>
<label rel="option_remote" class="type_radio" for="type_2">
<input type="radio" value="2" id="type_2" name="type" />
Remote</label>
<label rel="option_html" class="type_radio" for="type_1">
<input type="radio" value="1" id="type_1" name="type" />
HTML</label>
$('.type_radio').click(function() {
var r = $(this).attr('rel');
var arr = $(this).siblings().attr('rel');
$.each(arr, function(k, v) {
$('.' + v).addClass('dn');
});
$('.' + r).removeClass('dn');
return false;
});
我试图循环遍历带有类的元素,这些类引用特定触发器的“rel”属性并从中删除特定类。然后将该类应用于引用所选类的类。
所有标签都有类“type_radio”。
Anyone knows how can I get value of the attribute 'rel' from all siblings (labels of the radio button group) into array?
I've tried something like this, but it obviously doesn't work:
<label rel="option_local" class="type_radio" for="type_3">
<input type="radio" checked="checked" value="3" id="type_3" name="type" />
Local</label>
<label rel="option_remote" class="type_radio" for="type_2">
<input type="radio" value="2" id="type_2" name="type" />
Remote</label>
<label rel="option_html" class="type_radio" for="type_1">
<input type="radio" value="1" id="type_1" name="type" />
HTML</label>
$('.type_radio').click(function() {
var r = $(this).attr('rel');
var arr = $(this).siblings().attr('rel');
$.each(arr, function(k, v) {
$('.' + v).addClass('dn');
});
$('.' + r).removeClass('dn');
return false;
});
I'm trying to loop through elements with classes, which refer to the 'rel' attribute of the specific trigger and remove specific class from them. Then apply this class to the ones which refer to the selected one.
All labels have class 'type_radio'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的 - 我已经成功实现了 - 方法如下:
Ok - I've managed to achieve it - here's how: