繁体   English   中英

如何启用和禁用按钮

[英]How to Enable and Disable Buttons

我有4个按钮。 进入页面后,我只希望显示按钮1。 单击按钮1后,它会消失,只有按钮2可见。 单击按钮2后,它会消失,仅显示按钮3。 按钮5也会发生同样的事情。我们将不胜感激。

<html>
<script>
    function enableButton2() {
        document.getElementById("button2").disabled = false;
    }
function enableButton3() {
        document.getElementById("button3").disabled = false;
    }
function enableButton4() {
        document.getElementById("button4").disabled = false;
    }
function enableButton5() {
        document.getElementById("button5").disabled = false;
    }
</script>
</head>
<body>
    <input type="button" id="button1" value="button 1" onclick="enableButton2()"                  
    onclick="hidden" />
<input type="button" id="button2" value="button 2" disabled onclick="enableButton3()"   
    onclick="hidden" />
<input type="button" id="button3" value="button 3" disabled 
    onclick="enableButton4()" onclick="hidden"  />
<input type="button" id="button4" value="button 4" disabled onclick="enableButton5()" 
    onclick="hidden" />

无需为每个按钮使用不同的功能。 将下一个按钮的ID设置为单个功能的参数。 要隐藏第一个按钮,您需要设置其display样式,因此将this作为另一个参数传递。

HTML:

<input type="button" id="button1" value="button 1" onclick="enableButton(this, 'button2')" />
<input type="button" id="button2" value="button 2" disabled onclick="enableButton(this, 'button3')" />
<input type="button" id="button3" value="button 3" disabled onclick="enableButton(this, 'button4')" />
...

JS:

function enableButton(thisButton, nextButton) {
    thisButton.style.display = "none";
    document.getElementById(nextButton).disabled = false;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM