HTML: How to make a submit button with text + imag

2019-01-21 18:54发布

I would like to have a submit button which contains text and an image. Is this possible?

I can get the exact look I want with code that looks like:

<button type="button">
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>

... but I haven't found a way to have one of those for my forms. Is there a way to do that with an

<input type="submit" ...> 

element? Or am I forced to go the image or text way? Thanks for your help!

10条回答
干净又极端
2楼-- · 2019-01-21 19:34

input type="submit" is the best way to have a submit button in a form. The downside of this is that you cannot put anything other than text as its value. The button element can contain other HTML elements and content.

Try putting type="submit" instead of type="button" in your button element (source).

Pay particular attention however to the following from that page:

If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.

查看更多
虎瘦雄心在
3楼-- · 2019-01-21 19:40

I have found a very easy solution! If you have a form and you want to have a custom submit button you can use some code like this:

<button type="submit">
    <img src="login.png" onmouseover="this.src='login2.png';" onmouseout="this.src='login.png';" />
</button>

Or just direct it to a link of a page.

查看更多
倾城 Initia
4楼-- · 2019-01-21 19:41

Please refer to this link. You can have any button you want just use javascript to submit the form

http://www.w3schools.com/jsref/met_form_submit.asp

查看更多
地球回转人心会变
5楼-- · 2019-01-21 19:46

You're really close to the answer yourself

<button type="submit">
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>

Or, you can just remove the type-attribute

<button>
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>
查看更多
一纸荒年 Trace。
6楼-- · 2019-01-21 19:49

<input type="button" id="btnTexWrapped" style="background: url('http://i0006.photobucket.com/albums/0006/findstuff22/Backgrounds/bokeh2backgrounds.jpg');background-size:30px;width:50px;height:3em;" />

Change input style elements as you want to get the button you need.

I hope it was helpful.

查看更多
够拽才男人
7楼-- · 2019-01-21 19:49

Very interesting. I have been able to get my form to work but the resulting email displays:

imageField_x: 80 imageField_y: 17

at the bottom of the email that I get.

Here's my code for the buttons.

    <tr>
      <td><input type="image" src="images/sendmessage.gif" / ></td>
      <td colspan="2"><input type="image" src="images/printmessage.gif"onclick="window.print()"></td>
    </tr>

Maybe this will help you and me as well.

:-)

查看更多
登录 后发表回答