具有特定值的 jquery find() 复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15880789/
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 15:58:18 来源:igfitidea点击:
jquery find() checkbox with a certain value
提问by Lightwaxx
I have a list of checkboxes like so below wrapped in a div.
我有一个像下面这样包裹在div中的复选框列表。
<div>
<input type="checkbox" value="1" class="checkbox"/><br>
<input type="checkbox" value="2" class="checkbox"/><br>
<input type="checkbox" value="3" class="checkbox"/>
</div>
<select class="value">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
Using jquery, i would like on change for the select option, the checkbox with the value 1 to be checked.
使用 jquery,我想更改选择选项,选中值为 1 的复选框。
回答by tymeJV
Try:
尝试:
$(".value").change(function() {
$('input[type=checkbox][value=1]').prop('checked', true);
});
回答by pala?н
// Call the select list on change event
$(".value").change(function() {
// Reset all the check-boxes ckecked
$('input:checkbox').prop('checked', false);
// Set the chekbox with the same value as select option
$('input:checkbox[value="' + $(this).val() + '"]').prop('checked', true);
});
回答by xyz
You can try something like
你可以尝试类似的东西
$(".value").change(function() {
$(":checkbox[value="+this.value+"]").prop('checked',true)
});
回答by Santosh
Try below code
试试下面的代码
if($("Select.value").val()==1){
$("input[type='checkbox'][value=1]").attr('checked','checked');
}