我有两个fieldsets
:
<fieldset class="checkable">
<span class="as_cp_checkbox"></span>
<input type="hidden" name="register_condition_01" id="register_condition_01" value="no">
<label for="register_condition_01">data</label>
</fieldset>
<fieldset class="checkable">
<span class="as_cp_checkbox"></span>
<input type="hidden" name="register_condition_02" id="register_condition_02" value="yes">
<label for="register_condition_02">data</label>
</fieldset>
现在:如果我的输入值为是,我需要添加checked
类。span.as_cp_checkbox
我尝试这样做,但每次这个类都附加为 first fieldset
。
var checkable_fieldset = $('fieldset.checkable'),
checkable_fieldset_input = checkable_fieldset.find('input');
if (checkable_fieldset_input.val('yes')){
checkable_fieldset_input.parent(checkable_fieldset).prev().children('span').addClass('checked');
}
我如何为这个 prev 添加span
具有input
yes 值的类?