[英]Check a disabled radio button with jquery
我正在使用 JQUery Mobile 1.3.1 检查禁用的单选按钮(即无法单击的单选按钮)。 不幸的是,我的方法无法检查单选按钮禁用的单选按钮。 我已经尝试在这里找到答案,但还没有找到任何有用的东西。 这是我的代码:
<a href="#" id="activateRadio" data-role="button">Activate radio button flug!</a>
<input type="radio" name="radio1" id="radio-choice-1" value="choice-1" disabled />
和 JQuery 移动功能:
$('#activateRadio').click(function(){
//check if radio button is not checked
if ( ! $("input[name='radio3']").is(':checked') ) {
alert("The button was not checked. Now it should be checked!");
//remove disabled attribute
$("input[name='radio3']").removeAttr('disabled');
$("input[name='radio3']").attr('checked', 'checked');
}
else {
alert("The button is already checked!");
}
});
另一个问题也是如何在选中收音机时更改输入字段收音机的背景颜色。 这在 CSS 中看起来如何?
使用prop()
更改属性..attr 只是更改属性
if ( ! $("input[name='radio3']").is(':checked') ) {
alert("The button was not checked. Now it should be checked!");
//remove disabled attribute
$("input[name='radio3']").prop('disabled',false);
$("input[name='radio3']").prop('checked', true);
//or
$("input[name='radio3']").prop({'disabled':false',checked':true});
}
else {
alert("The button is already checked!");
}
并且不确定它是radio3还是radio1,因为我在这里找不到radio3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.