简体   繁体   English

如何使用javascript禁用和重新启用按钮?

[英]How do I disable and re-enable a button in with javascript?

I can easily disable a javascript button, and it works properly. 我可以轻松地禁用javascript按钮,并且它可以正常工作。 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. 在这种情况下, truefalse并非字符串。

You want the literal true and false Boolean values. 您需要字面值truefalse Boolean值。

startButton.disabled = true;

startButton.disabled = false;

The reason it sort of works (disables the element) is because a non empty string is truthy . 它之所以作品排序 (禁用元素)是因为一个非空字符串truthy。 So assigning 'false' to the disabled property has the same effect of setting it to true . 因此,将'false'分配给disabled属性具有将其设置为true效果。

<script>
function checkusers()
{
   var shouldEnable = document.getElementById('checkbox').value == 0;
   document.getElementById('add_button').disabled = shouldEnable;
}
</script>

you can try with 你可以尝试

document.getElementById('btn').disabled = !this.checked" document.getElementById('btn')。disabled =!this.checked“

 <input type="submit" name="btn" id="btn" value="submit" disabled/> <input type="checkbox" onchange="document.getElementById('btn').disabled = !this.checked"/> 

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

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