js如何禁用button按钮

时间:2017-03-20
本文章向大家介绍javascript如何禁用button按钮,要禁用button按钮,我们可以使用button的disabled属性,只要将其设置为true,则button就会被禁用,要起用button按钮,我们可以将disabled属性设为false。

问题:我们想知道如何禁用按钮。

实现方法:

要禁用button按钮,我们可以使用button的disabled属性,只要将其设置为true,则button就会被禁用

<html>
<body>
<button onclick="this.disabled='true'; alert(this.isDisabled);">Disable Me</button>
</body>
</html>

如果要起用button按钮,我们可以将disabled属性设为false,注意要这样设置:disabled=false, false不能加引号,是否无法起用button按钮

<html>
<body>
<button onclick="this.disabled=false; alert(this.isDisabled);">i am not disabled</button>
</body>
</html>

运行