0

私はこのコードを持っています:

<input type="button" onclick="alert('A message here');" value="Button"/>

標準のボタンの代わりに独自のイメージ ボタンを使用するにはどうすればよいですか?

4

4 に答える 4

3
<img src="{{your image url here}}" onclick="alert('A message here');" />

また

<div onclick="alert('A message here');" style="background: url({{your image url here}});background-repeat:no-repeat; width:150px; height:100px;"></div>
于 2013-11-07T00:20:57.700 に答える
1

<button>の代わりに タグを使用する<input type="button">と、HTML コンテンツで埋めることができます。

<button onclick="alert('A message here');" type="button">
  <img src="myurl">
</button>

ドキュメント: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

例: http://jsbin.com/ezeFaYU/1/edit

于 2013-11-07T00:23:38.770 に答える
0

画像ボタン自体はありませんが、JavaScript を使用しているため、クリック イベントを画像に追加できます。以下のフィドルを参照してください。

<img class="button" src="http://goo.gl/UGQl0i" width="100" height="100" onclick="alert('A message here');" >

http://jsfiddle.net/CN8Js/

于 2013-11-07T00:24:35.203 に答える
0

This should work. Just replace "img.png" with your image.

<img src = "img.png" onclick="alert('A message here');"/>
于 2013-11-07T00:25:27.597 に答える