[英]Change the button from disabled='true' to 'false'
I have written a code regarding a submit form. 我已经编写了有关提交表单的代码。 When I click the
button(Download)
, the status is disabled, and I want to make it enabled, but if I add an alert box between submit and make the disable false, it works. 当我单击
button(Download)
,状态为禁用,我想启用它,但是如果我在“提交”与“禁用”之间添加一个警告框,则该状态有效。 If I remove the alert box, it doesn't work. 如果我删除警报框,则它不起作用。 Is that the time problem or else?
那是时间问题吗? How can I solve it?
我该如何解决?
How can I change the button from disabled='true'
to 'false'
? 如何将按钮从
disabled='true'
更改为'false'
?
Here is my code: 这是我的代码:
<div id="fm" class="btnStyleFunc" onclick="disabled='true';submitform()">
<a><span>Download</span></a>
</div>
function submitform(){
var element1 = document.getElementById('form');
if (element1 != null){
} else {
}
document.getElementById('form').submit();
alert('test'); // <--------
document.getElementById('fm').disabled = false;
}
Try this: 尝试这个:
function disabledFunc(id)
{
var divObj = document.getElementById(id);
divObj.disabled = false;
}
And call the function with the button id: 并使用按钮id调用该函数:
disabledFunc('fm');
Hope it helps! 希望能帮助到你!
Use this: 用这个:
<div id="fm" class="btnStyleFunc" onclick="this.disabled=true;submitform()">
<a><span>Download</span></a>
</div>
Of course, the element is a DIV and not a button, so I don't know how well disabled
will work on it... 当然,该元素是DIV而不是按钮,因此我不知道
disabled
它的程度如何...
As Farish and MrXenotype have pointed out, the "disabled" attribute is meaningless to a div
element. 正如Farish和MrXenotype所指出的那样,“禁用”属性对
div
元素毫无意义。 It can be added dynamically but won't affect the behavior. 可以动态添加它,但不会影响行为。 But I understand why you might want to use a
div
instead of a button, especially if you have spent time customizing your style sheet to get it to look the way you want. 但我知道为什么您可能想使用
div
而不是按钮,尤其是如果您花了一些时间自定义样式表以使其看起来像您想要的方式时。
I think you can get the behavior you want though by making a small change: 我认为您可以通过进行一些小的更改来获得所需的行为:
<div id="fm" class="btnStyleFunc" onclick="this.onclick=null;submitform()">
<a><span>Download</span></a>
</div>
Basically when your onclick handler executes, you disconnect it from the div
element. 基本上,当您的onclick处理程序执行时,您就将其与
div
元素断开连接。 Now when someone clicks your "button" a second time it will do nothing. 现在,当有人第二次单击您的“按钮”时,它什么也不会做。 During the
onclick
you might want to also change your class to something other than btnStyleFunc - perhaps a new class called btnStyleFuncDisabled
. 在
onclick
期间,您可能还想将您的类更改为btnStyleFunc以外的其他类-也许是一个名为btnStyleFuncDisabled
的新类。 Then you can modify your style sheet so that any div
element with that class appears greyed out. 然后,您可以修改样式表,以使具有该类的所有
div
元素均显示为灰色。
<div id="fm" class="btnStyleFunc"
onclick="this.className='btnStyleFuncDisabled'; this.onclick = null; dosubmit(this)">
<a><span>Download</span></a>
</div>
Note that: 注意:
<div id="fm" class="btnStyleFunc" onclick="disabled='true';submitform()">
will create a global variable disabled
with the string value 'true', and 将创建一个
disabled
的全局变量,其字符串值为“ true”,并且
document.getElementById('fm').disabled = false;
compares the disabled
property of an element with id "fm" to the boolean value false
. 将ID为“ fm”的元素的
disabled
属性与布尔值false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.