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:
我可以轻松禁用javascript按钮,它可以正常工作。我的问题是,当我尝试重新启用该按钮时,它不会重新启用。这就是我正在做的事情:
<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?
为什么这不起作用,我该怎么做才能使它工作?
3 个解决方案
#1
75
true
and false
are not meant to be strings in this context.
在这种情况下,true和false并不意味着是字符串。
You want the literal true
and false
Boolean
values.
您需要文字的true和false布尔值。
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
.
它有效的原因(禁用元素)是因为非空字符串是真的。因此,将“false”分配给disabled属性与将其设置为true具有相同的效果。
#2
5
<script>
function checkusers()
{
var shouldEnable = document.getElementById('checkbox').value == 0;
document.getElementById('add_button').disabled = shouldEnable;
}
</script>
#3
1
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"/>
#1
75
true
and false
are not meant to be strings in this context.
在这种情况下,true和false并不意味着是字符串。
You want the literal true
and false
Boolean
values.
您需要文字的true和false布尔值。
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
.
它有效的原因(禁用元素)是因为非空字符串是真的。因此,将“false”分配给disabled属性与将其设置为true具有相同的效果。
#2
5
<script>
function checkusers()
{
var shouldEnable = document.getElementById('checkbox').value == 0;
document.getElementById('add_button').disabled = shouldEnable;
}
</script>
#3
1
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"/>