HTML: How to make a submit button with text + image in it?

后端 未结 10 775
抹茶落季
抹茶落季 2020-12-13 07:09

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:

相关标签:
10条回答
  • 2020-12-13 07:20

    <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.

    0 讨论(0)
  • 2020-12-13 07:20

    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.

    :-)

    0 讨论(0)
  • 2020-12-13 07:29

    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>
    
    0 讨论(0)
  • 2020-12-13 07:36

    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.

    0 讨论(0)
提交回复
热议问题