Javascript “故障设置”;勾选“;属性设置为jquery复选框
我想将Javascript “故障设置”;勾选“;属性设置为jquery复选框,javascript,jquery,Javascript,Jquery,我想将div中的所有复选框设置为选中特定单选按钮时选中的复选框。这是我尝试过的,但不起作用。我尝试了prop()和attr() 这是我的 衡平法 少展示 HDFC动态基金HDFC动态基金HDFC动态目前投资50000卢比 50,00000卢比 动态基金动态基金动态基金动态基金 50,00000卢比 只有在页面加载时选中了#radio1时,才能进行检查。如果您想让它在用户检查/取消选中时进行检查,请使用on() 请注意,在下面的工作示例中,我们绑定到one的onchange。这将在用户选中#ra
div中的所有复选框设置为选中特定单选按钮时选中的复选框。这是我尝试过的,但不起作用。我尝试了prop()
和attr()
这是我的
衡平法
少展示
HDFC动态基金HDFC动态基金HDFC动态目前投资50000卢比
50,00000卢比
动态基金动态基金动态基金动态基金
50,00000卢比
只有在页面加载时选中了#radio1
时,才能进行检查。如果您想让它在用户检查/取消选中时进行检查,请使用on()
请注意,在下面的工作示例中,我们绑定到one
的onchange
。这将在用户选中#radio2
时保留复选框的选中/取消选中:
let$checkbox=$('.checkbox div').find('input[type=checkbox]);
$('input[name=“one”]”)。在('change',function()上{
if($(this).is(':checked')&&&$(this.attr('id')=='radio1')
{
$checkbox.prop('checked',true);
}
其他的
{
$checkbox.prop('checked',false);
}
});代码>
衡平法
少展示
HDFC动态基金HDFC动态基金HDFC动态目前投资50000卢比
50,00000卢比
动态基金动态基金动态基金动态基金
50,00000卢比
您应该试试这个
$('#radio1').on('click',function(){
$('.checkbox-div').find('input[type="checkbox"]').attr('checked',$(this).prop('checked'));
});
.prop('checked',true)代码>非.attr('checked','true')
(布尔值周围没有引号)如果用户选中#radio2
,则不会考虑此值的可能重复项。
<input type = "radio" id="radio1" name = "one">
<input type = "radio" id="radio2" name = "one">
<table class="table funds-table">
<thead class="table-head">
<tr>
<th id="equity-text">EQUITY</th>
<th id="eq-show-less">SHOW LESS</th>
</tr>
</thead>
<tbody id = "equity-body">
<tr>
<td class = "fund-name">
<div class = "col-xs-1 padding-lr-zero checkbox-div"><input type="checkbox" id = "checkbox1">
<label for="checkbox1"><span class="checkbox"><img src="icons/check_dis.png"></span></label></div>
<div class = "col-xs-11 fund-name-div"><span class = "span-fund-name">HDFC DYNAMIC FUND HDFC DYNAMIC FUND HDFC DYNAMIC</span><p class = "currently-inv"> Currently invested <span class = "curr-span-amt">Rs. 50,000</span></p></div>
</td>
<td class = "fund-amount"><p class = "fund-amount-inner">Rs. 50,00,000</p></td>
</tr>
<tr>
<td class = "fund-name">
<div class = "col-xs-1 padding-lr-zero checkbox-div"><input type="checkbox" id = "checkbox2">
<label for="checkbox2"><span class="checkbox"><img src="icons/check_dis.png"></span></label></div>
<div class = "col-xs-11 fund-name-div"><span class = "span-fund-name">HDFC DYNAMIC FUND HDFC DYNAMIC FUND HDFC DYNAMIC</span></div>
</td>
<td class = "fund-amount"><p class = "fund-amount-inner">Rs. 50,00,000</p></td>
</tr>
</tbody>
$('#radio1').on('click',function(){
$('.checkbox-div').find('input[type="checkbox"]').attr('checked',$(this).prop('checked'));
});