Html 使图像像按钮一样
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16131988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making an image act like a button
提问by Kevin
I'm working on a simple HTML page where I have this image that I want to act as a button.
我正在一个简单的 HTML 页面上工作,我有这个图像,我想作为一个按钮。
Here is the code for my image:
这是我的图像的代码:
<div style="position: absolute; left: 10px; top: 40px;">
<img src="logg.png" width="114" height="38">
</div>
And basically I want to add this functionality into it:
基本上我想将此功能添加到其中:
<div>
<input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="Submit"/>
</div>
The text on the button itself that says Submit is not needed as my image has the text it needs.
不需要按钮本身上的文本,因为我的图像有它需要的文本。
So anyway, is this possible? and if so, How? :)
那么无论如何,这可能吗?如果是这样,如何?:)
回答by VoteyDisciple
It sounds like you want an image
button:
听起来你想要一个image
按钮:
<input type="image" src="logg.png" name="saveForm" class="btTxt submit" id="saveForm" />
Alternatively, you can use CSS to make the existing submit
button use your image as its background.
或者,您可以使用 CSS 使现有submit
按钮使用您的图像作为其背景。
In any case, you don'twant a separate <img />
element on the page.
在任何情况下,您都不希望<img />
页面上有单独的元素。
回答by mburm
You could implement a JavaScript block which contains a function with your needs.
您可以实现一个包含您需要的函数的 JavaScript 块。
<div style="position: absolute; left: 10px; top: 40px;">
<img src="logg.png" width="114" height="38" onclick="DoSomething();" />
</div>
回答by Mudassir Hasan
You could use an image submit button:
您可以使用图像提交按钮:
<input type="image" id="saveform" src="logg.png " alt="Submit Form" />