我需要帮助来取消或选中同一个单选按钮,如果该按钮已经被选中?我有一个jQuery函数,用于启用或禁用其他单选按钮,如果已经被选中,现在我想添加一些功能,用于选中或取消选中同一个单选按钮。
(function ($) {
$(document).ready(function () {
$('input:radio').click(function(){
var $inputs = $('input:radio')
if($(this).is(':checked')){
$inputs.not(this).prop('disabled',true);
}else{
$inputs.prop('disabled',false);
}
})
});
})(jQuery);
<input type="radio" value="Test1" />Test1
<input type="radio" value="Test2" />Test2
<input type="radio" value="Test1" />Test1
<input type="radio" value="Test2" />Test2