Jquery select selection 电台
Jquery select radio on selection
我正在尝试通过 jquery 来选中和取消选中单选框。
例如; when radio ['mainfield'] with the value of '1' is selected – radio ['otherfield'] with the value of 1 to be selected.
然后,如果 ['mainfield'] 更改为 1 以外的值,请取消选中 ['otherfield'];
希望我所追求的是有意义的。看起来很简单,但我无法真正让它做我想做的事。
我在这里做了一个 fiddle 尝试:
http://jsfiddle.net/brandrally/0zb521v4/2/
// Javascript //
$(document).ready(function(){
$('input:radio[name="mainfield"]').change(function(){
if ($(this).val()==1) {
$('input:radio[name="otherfield"][value=1].prop('checked', false);
}
if ($(this).val()==2) {
$('input:radio[name="otherfield"][value=1].prop('checked', false);
}
});
});
// HTML //
<div style="padding: 0 0 10px 0;">
<label><input name="mainfield" type="radio" value="1"> Apples </label>
<label><input name="mainfield" type="radio" value="2"> Oranges</label>
</div>
<div>
<label><input name="otherfield" type="radio" value="1"> Yes [ Automatically Check and Uncheck this box if name='mainfield' = 1 ] </label>
<label><input name="otherfield" type="radio" value="2"> No</label>
</div>
只是一个杂乱的 ') 打字错误导致此错误无法正常工作。
我正在尝试通过 jquery 来选中和取消选中单选框。
例如; when radio ['mainfield'] with the value of '1' is selected – radio ['otherfield'] with the value of 1 to be selected.
然后,如果 ['mainfield'] 更改为 1 以外的值,请取消选中 ['otherfield'];
希望我所追求的是有意义的。看起来很简单,但我无法真正让它做我想做的事。
我在这里做了一个 fiddle 尝试: http://jsfiddle.net/brandrally/0zb521v4/2/
// Javascript //
$(document).ready(function(){
$('input:radio[name="mainfield"]').change(function(){
if ($(this).val()==1) {
$('input:radio[name="otherfield"][value=1].prop('checked', false);
}
if ($(this).val()==2) {
$('input:radio[name="otherfield"][value=1].prop('checked', false);
}
});
});
// HTML //
<div style="padding: 0 0 10px 0;">
<label><input name="mainfield" type="radio" value="1"> Apples </label>
<label><input name="mainfield" type="radio" value="2"> Oranges</label>
</div>
<div>
<label><input name="otherfield" type="radio" value="1"> Yes [ Automatically Check and Uncheck this box if name='mainfield' = 1 ] </label>
<label><input name="otherfield" type="radio" value="2"> No</label>
</div>
只是一个杂乱的 ') 打字错误导致此错误无法正常工作。