我有一组带有激光选项“其他”的单选按钮和一个输入字段类型文本
。默认情况下,输入字段被禁用,如果您单击“其他”单选按钮,则该字段将被启用。如果单选按钮的选择发生更改,如何禁用输入字段?
这是我的代码:
$(document).ready(function(){
$("#text-inputt").prop('disabled', true)
});
$("#lastt").click(function(){ $("#text-inputt").prop('disabled', false/true)});
如果您更改单选选择,此代码不会禁用输入字段。
更新1 我正在尝试这个:
$(document).ready(function(){
$("#text-inputt").prop('disabled', true);
});
$("#lastt").click(function(){
if($(this).is(':checked')) {
$("#text-inputt").prop("disabled", false);
} else {
$("#text-inputt").prop("disabled", true);
}
});
但是如果您更改单选按钮,则不会将输入设置为禁用。
最佳答案
你能做到like this
$(document).ready(function(){
$("#text-inputt").prop('disabled', true);
$('input[type=radio]').click(function(){
if($(this).prop('id') == "lastt"){
$("#text-inputt").prop("disabled", false);
}else{
$("#text-inputt").prop("disabled", true);
}
});
});
关于javascript - 如何根据单选按钮切换启用/禁用输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36400042/