简体   繁体   English

带图像的输入类型按钮

[英]Input type button with image

I want an event to be triggered when the image is clicked, but I cannot figure out how to make that happen. 我希望在单击图像时触发一个事件,但是我不知道如何实现。 Is it possible for an event to be triggered when an image is clicked? 单击图像是否有可能触发事件?

<form>
  <input type="button" name="button" value="Download" onclick="passWord()" class="button"/>
</form>

jsfiddle: https://jsfiddle.net/29mf5wf9/ jsfiddle: https ://jsfiddle.net/29mf5wf9/

See this fiddle 看到这个小提琴

You can use image instead of button for input type . 您可以使用image而不是button作为input type It will still be a button. 它仍然是一个按钮。

HTML 的HTML

<input type="image" src="image/path" name="button" value="Download" onclick="passWord()" class="button"/>

According to the docs 根据文档

The <input type="image"> is a graphical submit button. <input type="image">是一个图形提交按钮。

See the updated fiddle with a javascript function working.. 请参阅更新的小提琴,其中包含javascript函数。

You need to specify image in the type. 您需要在类型中指定图片。

<form>
    <input type="image" src="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png" name="button" value="Download" onclick="passWord()" class="button"/>
</form> 

在这里您可以找到信息: http : //www.w3schools.com/tags/att_input_src.asp

<input type="image" src="your_image.png" name="button" value="Download" alt="Download" onclick="passWord();" class="button" width="your_image_width" height="your_image_height">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM