开发者

Cannot enable XHTML submit input/button which is disabled by default

开发者 https://www.devze.com 2023-04-03 19:23 出处:网络
I have this simple button in XHTML: <input type=\"submit\" name=\"submit\" value=\"Test\" disabled=\"disabled\" onmouseover=\"this.disabled=\'\'\" />

I have this simple button in XHTML:

<input type="submit" name="submit" value="Test" disabled="disabled" onmouseover="this.disabled=''" />

The problem is, no matter what I try, when I hover over the button, it won't re-enable from the disabled attribute it has. In XHTML, you are required to use disabled="disabled" which seems to completely break the option to enable/disable it with JavaScript. I've 开发者_开发技巧tried running this.disabled='', this.disabled=false, and even this.removeAttribute('disabled') but nothing seems to be capable of re-enabling the button. Weird thing is, if I remove the ='disabled' part of the attribute (making it invalid XHTML), the script enables the button just fine. Is this not possible without using invalid XHTML?

Note: I'd really prefer to only use JavaScript for this specific example, not jQuery.

I thought this would be something simple that would take like 5 seconds but apparently not.


Disabled elements for some reason do not seem to fire mouseover/out events along with click.

The following is not the best solution in the world, but you can wrap it in another element and use the wrapping element's mouseover event to enable it.

<div style="display:inline-block;padding:1px;" onmouseover="document.getElementById('submit').disabled=false">
    <input type="submit" id="submit" name="submit" value="Test" disabled="disabled" />
</div>


disabled=false is correct.

The problem is that a disabled element doesn't receive events. See the question Javascript OnMouseOver and Out disable/re-enable item problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号