jQueryイベント

JavaScript入門

 
■概要
 
jQueryを使うとイベントを簡単に指定できます。
onを使うと指定できます。

$(‘#objId’).on(‘click’, function(event){
 alert(‘jQueryイベント’);
})

 
■例

<button id=”test-btn” style=”background-color: grey; border: none;”>テストボタン</button>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
<script>
 $(‘#test-btn’).on(‘mouseover’, function(event) { $(‘#test-btn’).css(‘color’, ‘black’); });
 $(‘#test-btn’).on(‘mouseout’, function(event) { $(‘#test-btn’).css(‘color’, ‘white’); });
 $(‘#test-btn’).on(‘mousedown’, function(event) { $(‘#test-btn’).css(‘color’, ‘blue’); });
</script>

出力結果



 
 
 
 

当サイトは広告を含めています。広告のクリックによる収益は全て当サイトの管理、維持、コンテンツ製作に使われます。

 

Team ladybird
タイトルとURLをコピーしました