【发布时间】:2013-11-18 11:45:41
【问题描述】:
我有这个代码:
<input type="button" onclick="alert('A message here');" value="Button"/>
如何使用我自己的图像按钮而不是标准按钮?
【问题讨论】:
我有这个代码:
<input type="button" onclick="alert('A message here');" value="Button"/>
如何使用我自己的图像按钮而不是标准按钮?
【问题讨论】:
<img src="{{your image url here}}" onclick="alert('A message here');" />
或
<div onclick="alert('A message here');" style="background: url({{your image url here}});background-repeat:no-repeat; width:150px; height:100px;"></div>
【讨论】:
如果你使用<button>标签而不是<input type="button">,你可以用HTML内容填充它:
<button onclick="alert('A message here');" type="button">
<img src="myurl">
</button>
文档:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
【讨论】:
本身没有图像按钮,但由于您使用的是 javascript,因此您可以将点击事件添加到图像中。请参阅下面的小提琴。
<img class="button" src="http://goo.gl/UGQl0i" width="100" height="100" onclick="alert('A message here');" >
【讨论】:
这应该有效。只需将“img.png”替换为您的图片即可。
<img src = "img.png" onclick="alert('A message here');"/>
【讨论】: