[HTML] JavaScriptで押されたボタンの値を取り出す

 以下にサンプルコード。

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript">
      function buttonPush(obj) {
        document.getElementById('value').innerHTML = obj.value;
      }
    </script>
  </head>

  <body>
    <input type="button" value="1" onclick="buttonPush(this);">
    <input type="button" value="2" onclick="buttonPush(this);">
    <input type="button" value="3" onclick="buttonPush(this);">
    <input type="button" value="4" onclick="buttonPush(this);">
    <input type="button" value="5" onclick="buttonPush(this);">
    <input type="button" value="6" onclick="buttonPush(this);">
    <input type="button" value="7" onclick="buttonPush(this);">
    <input type="button" value="8" onclick="buttonPush(this);">
    <input type="button" value="9" onclick="buttonPush(this);">
    <input type="button" value="0" onclick="buttonPush(this);">
    <p><span id="value"></span></p>
  </body>
</html>

コメント

このブログの人気の投稿

[Minecraft: Wii U Edition] SEED:306959825 海底神殿、森の洋館、メサがある有名神マップ [ネタバレ注意]

【パソコン】富士通LIFEBOOKでUSBブートする

浴室の電球をLEDへ交換(National製白熱灯照明RL93013)

【パソコン】 WiinUProでSwitchプロ・コントローラーをPCで使ってみる

VOBファイルの結合

Windows XPのLANを有効化/無効化する

[Minecraft Bedrock] Lifeboatってなんだ?!