4
关注
2120
浏览

jQuery检测是否在加载时选择了单选按钮

查看全部 3 个回答

张明 未验证用户 用户来自于: 广东省
2020-09-16 09:02

你可以定义检查函数然后调用它在就绪功能,并且还当你连接喜欢你change事件:

$(function(){ 
    //First call for the load 
    checkRadioButtons(); 

    //Second call for change event 
    $("input[type=radio]").change(checkRadioButtons); 
}); 

$(function() { 
 
    checkRadioButtons(); 
 
    $("input[type=radio]").change(checkRadioButtons); 
 
}); 
 

 
var checkRadioButtons = function() { 
 
    if ($('.SelectMarital').is(':checked') && $('.SelectPrice').is(':checked')) { 
 
    $("#salary").removeClass('disabled'); 
 
    } else { 
 
    $("#salary").addClass('disabled'); 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">script> 
 

 
<input class="SelectMarital" id="marital1" type="radio" name="marital" value="1" checked/> Marital 1 
 
<input class="SelectMarital" id="marital1" type="radio" name="marital" value="2" /> Marital 2 
 
<br> 
 
<input class="SelectPrice" id="price1" type="radio" name="price" value="1" checked/> Price 1 
 
<input class="SelectPrice" id="price2" type="radio" name="price" value="2" /> Price 2 
 
<br><br> 
 
<a href="#" id="salary" class="btn disabled">Next Stepa>

关于作者

问题动态

发布时间
2020-09-15 15:51
更新时间
2022-09-15 16:04
关注人数
4 人关注
个人工作笔记 Powered BY WeCenter V4.1.0 © 2024 粤ICP备2020123311号