js代码实现:
document.getElementById("表单组件ID").disabled=true;
document.getElementById("表单组件ID").disabled=false;
jQuery代码实现:
//两种方法设置disabled属性
$('#qwbminput').attr("disabled",true);
$('#qwbminput').attr("disabled","disabled");
//三种方法移除disabled属性
$('#qwbminput').attr("disabled",false);
$('#qwbminput').removeAttr("disabled");
$('#qwbminput').attr("disabled","");
测试代码:
<button id="qwbminput">表单</button>
<br><br>
<button onclick='qwbmtrue()'>true</button>
<button onclick='qwbmfalse()'>false</button>
<script src="https://lib.baomitu.com/jquery/3.5.1/jquery.js"></script>
<script>
function qwbmtrue(){
$('#qwbminput').attr("disabled",true);
}
function qwbmfalse(){
$('#qwbminput').attr("disabled",false);
}
</script>