我有一个这样的按钮:
<input id="Button" type="button" value="+" style="background-color:grey" onclick="Me();"/>
当我需要时,我如何禁用和启用它?我已经尝试了禁用=“禁用”,但启用它回来是一个问题。我试着把它设置回false,但那没有启用它。
我有一个这样的按钮:
<input id="Button" type="button" value="+" style="background-color:grey" onclick="Me();"/>
当我需要时,我如何禁用和启用它?我已经尝试了禁用=“禁用”,但启用它回来是一个问题。我试着把它设置回false,但那没有启用它。
当前回答
disable属性只有一个参数。如果你想重新启用它,你必须删除整个东西,而不仅仅是改变值。
其他回答
$(".btncancel").button({ disabled: true });
这里'btncancel'是按钮的类名。
<!--Button Disable Script-->
<script type="text/javascript">
function DisableButton() {
document.getElementById("<%=btnSave.ClientID %>").disabled = true;
}
window.onbeforeunload = DisableButton;
</script>
<!--Button Disable Script-->
使用jQuery,你可以在一行中完成
//Enable
$('#Button').prop('disabled', false)
//Disable
$('#Button').prop('disabled', true)
只需Vanilla JavaScript就可以很容易地做到这一点,不需要任何库。
启用按钮
document.getElementById("Button").disabled=false;
禁用按钮
document.getElementById("Button").disabled=true;
不需要外部库。
使用JavaScript禁用/启用html输入按钮:
(以及与裁判反应。取代“elementRef。如果不使用React,元素选择current)
elementRef.current.setAttribute('disabled', 'disabled');
启用:
elementRef.current.removeAttribute('disabled');