版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22708467/article/details/85162422
判断如果输入框有值,选中“是”
if($("#hosNum").val()!=""){
$("#isHos1").attr("checked", "checked");//不选中
$("#isHos2").removeAttr("checked");//选中
$("#hosNum").attr("readOnly",false);//非只读
}
根据radio的选择控制输入框是否只读
$(function() {
$(":radio[name='isHos']").click(function() {
if($(this).val()==0){//选中的是否
$("#hosNum").val("");//清空
$("#hosNum").attr("readOnly",true);//只读
}else{
$("#hosNum").attr("readOnly",false);
}
});
});
以下是html代码
是否填写号码
<input type="radio" name="isHos" value="1" id="isHos1">是
<input type="radio" name="isHos" value="0" checked id="isHos2">否
号码:<input type="text" id="hosNum" name="hosNum" value="${unifyMasterPerson.hosNum}" readonly="true" />
以下是样式展示