「JavaScript」イベントonmouseupの使い方

環境
Windows 10 home 64bit
Google Chrome 103.0.5060.114

構文
document.getElementById(要素).onmouseup = function(){ 処理コード };
onmouseup は GlobalEventHandlers ミックスインのプロパティで、mouseupイベントを処理するイベントハンドラーです。
mouseup イベントは、ユーザーがマウスボタンを離したときに発行されます。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<div id="cft" >
<p>test</p>
</div>
<script>
document.getElementById('cft').onmouseup = function(){
alert('ユーザーがマウスボタンを離しました');
};
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <div id="cft" > <p>test</p> </div> <script> document.getElementById('cft').onmouseup = function(){ alert('ユーザーがマウスボタンを離しました'); }; </script> </body> </html>
<!DOCTYPE html>
<html>
<body>

<div id="cft" >
  <p>test</p>
</div>
<script>

document.getElementById('cft').onmouseup = function(){ 
  alert('ユーザーがマウスボタンを離しました');
};

</script>

</body>
</html>

実行結果
文字「test」をクリックしてマウスから離れた時に「ユーザーがマウスボタンを離しました」が表示されます。

JavaScript

Posted by arkgame