如何将图像用作提交按钮?

时间:2013-01-07 16:17:16

标签: html form-submit submit-button

有人可以帮忙更改此内容以合并名为BUTTON1.JPG的图片而不是标准的submit按钮吗?

<form id='formName' name='formName' onsubmit='redirect();return false;'>
    <div class="style7">
        <input type='text' id='userInput' name='userInput' value=''>
        <input type='submit' name='submit' value='Submit'>
    </div>
</form> 

6 个答案:

答案 0 :(得分:67)

使用image类型输入:

<input type="image" src="/Button1.jpg" border="0" alt="Submit" />

完整的HTML:

<form id='formName' name='formName' onsubmit='redirect();return false;'>
  <div class="style7">
    <input type='text' id='userInput' name='userInput' value=''>
    <input type="image" name="submit" src="https://jekyllcodex.org/uploads/grumpycat.jpg" border="0" alt="Submit" style="width: 50px;" />
  </div>
</form> 

答案 1 :(得分:16)

为什么不:

<button type="submit">
<img src="mybutton.jpg" />
</button>

答案 2 :(得分:6)

使用CSS:

input[type=submit] {

background:url("BUTTON1.jpg");

}

对于HTML:

<input type="submit" value="Login" style="background:url("BUTTON1.jpg");">

答案 3 :(得分:4)

只需删除边框并在css中添加背景图片

示例:

$("#form").on('submit', function() {
   alert($("#submit-icon").val());
});
#submit-icon {
  background-image: url("https://pixabay.com/static/uploads/photo/2016/10/18/21/22/california-1751455__340.jpg"); /* Change url to wanted image */
  background-size: cover;
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form">
  <input type="submit" id="submit-icon" value="test">
</form>

答案 4 :(得分:1)

<form id='formName' name='formName' onsubmit='redirect();return false;'>
        <div class="style7">
    <input type='text' id='userInput' name='userInput' value=''>
    <img src="BUTTON1.JPG" onclick="document.forms['formName'].submit();">
</div>
</form>

答案 5 :(得分:-5)

HTML:

<button type="submit" name="submit" class="button">
  <img src="images/free.png" />
</button>

CSS:

.button {  }