本文實例講述了JavaScript控制按鈕可用或不可用的方法。分享給大家供大家參考。具體如下:
下面的JS代碼通過按鈕對象的disabled屬性控制按鈕是否可用
<!DOCTYPE html><html><body><form>Buttons:<input type="button" id="firstbtn" value="OK"><input type="button" id="secondbtn" value="OK"></form><p>Click the button below to disable the first button above.</p><button onclick="disableElement()">Disable button</button><script>function disableElement(){document.getElementById("firstbtn").disabled=true;}</script></body></html>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答