Prototype-event-isleftclick

提供:Dev Guides
2020年6月23日 (火) 02:07時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

プロトタイプ-イベントisLeftClick()メソッド

このメソッドは、ボタン関連のマウスイベントが「左」(実際にはプライマリ)ボタンに関するものであったかどうかを判断します。

構文

Event.isLeftClick(event);

戻り値

左ボタンが押された場合、trueを返します。

-MSIEでは機能しないようです。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
        //Register event 'click' and associated call back.
         Event.observe(document, 'click', respondToClick);

        //Callback function to handle the event.
         function respondToClick(event) {
            var bool = Event.isLeftClick(event);

            if ( bool ) {
               alert("Left button is pressed...." );
            }
         }
      </script>
   </head>

   <body>
      <p id = "note"> Click anywhere to see the result.</p>
      <p>This example may not work in IE.</p>
      <p id = "para1">This is paragraph 1</p>
      <p id = "para2">This is paragraph 2</p>
      <div id = "division">This is divsion.</div>
   </body>
</html>

出力