如何禁用并重新启用JavaScript中的按钮? [英] How do I disable and re-enable a button in with javascript?

查看:326
本文介绍了如何禁用并重新启用JavaScript中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以轻松禁用一个javascript按钮,并且它可以正常工作。我的问题是,当我尝试重新启用该按钮时,它不会重新启用。以下是我正在做的事:

 < script type =text / javascript> 
函数startCombine(startButton){

startButton.disabled ='true';

startButton.disabled ='false';

}
< / script>
< input type ='button'id ='start'value ='合并所选视频'
onclick ='startCombine(this);'>

为什么不能正常工作,我该怎么做才能使它工作?

解决方案

true 和 false 在这种情况下并不意味着是字符串。

您希望文字 false 布尔值值。

  startButton.disabled = true; 

startButton.disabled = false;

类型的原因(禁用元素)是因为非空字符串是 truthy 。因此,将'false'分配给 disabled 属性具有将它设置为 true的相同效果


I can easily disable a javascript button, and it works properly. My issue is that when I try to re-enable that button, it does not re-enable. Here's what I'm doing:

<script type="text/javascript">
    function startCombine(startButton) {

        startButton.disabled = 'true';

        startButton.disabled = 'false';

    }
</script>
<input type='button' id='start' value='Combine Selected Videos'
onclick='startCombine(this);'>

Why isn't this working, and what can I do to make it work?

解决方案

true and false are not meant to be strings in this context.

You want the literal true and false Boolean values.

startButton.disabled = true;

startButton.disabled = false;

The reason it sort of works (disables the element) is because a non empty string is truthy. So assigning 'false' to the disabled property has the same effect of setting it to true.

这篇关于如何禁用并重新启用JavaScript中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆