0
任何人都知道如何從屬於所有兄弟姐妹(單選按鈕組的標籤)的屬性'rel'到數組中的值?jquery兄弟姐妹屬性數組
我已經試過這樣的事情,但它顯然是行不通的:
<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;
});
我通過與類元素,它指的是特定觸發的「相對」屬性試圖循環並從中刪除特定的課程。然後將這個類應用到引用所選內容的類。
所有的標籤都有'type_radio'類。