admin管理员组文章数量:1296287
I have an image as a button..I want to disable the image onclick...How can I do that?
<input type="image" src="someimage.png" height="20px" width="20px" name="button" />
I have an image as a button..I want to disable the image onclick...How can I do that?
<input type="image" src="someimage.png" height="20px" width="20px" name="button" />
Share
Improve this question
asked Jul 29, 2013 at 20:11
user2605321user2605321
932 gold badges5 silver badges11 bronze badges
3
- 2 disable the image or the input? were do you click? – Sergio Commented Jul 29, 2013 at 20:13
- The image is acting as a button..So disabling the image would eventually disable the input./button – user2605321 Commented Jul 29, 2013 at 20:13
-
2
if you're just removing the clickable functionality, why are you using
input
at all? – user428517 Commented Jul 29, 2013 at 20:16
3 Answers
Reset to default 5html(add id):
<input id="btn" type="image" src="someimage.png" height="20px" width="20px" name="button" />
js:
document.getElementById("btn").onclick = function(){
this.disabled = true
}
http://jsfiddle/Dtgb4/
Or you can just add attribute onclick="this.disabled = true"
update for ment:
You can use CSS rule :disabled
for styling disabled buttons
http://jsfiddle/Dtgb4/1/
P.S. pseudo-class :disabled only for modern browsers(not for IE8-).
Unless you have a specific reason to use the input type, you shouldn't be using it for image.
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
use the image type, and no onclick handler.
You can use
<button height="20px" width="20px" name="button"><img src="someimage.png"/></button>
and now you can disable button as normal as everything
本文标签: javascriptDisabling input typequotimagequot as buttonStack Overflow
版权声明:本文标题:javascript - Disabling input type="image" as button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741623583a2388954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论