如何在透過其他事件生成元素上繫結 jQuery 事件?
使用 jQuery on() 方法來繫結透過其他事件生成元素上的 jQuery 事件。你可以嘗試執行以下程式碼,瞭解如何使用 on() 方法來繫結 jQuery 事件
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).on({
mouseenter: function (e) {
alert('mouse enter');
},
mouseleave: function (e) {
alert('mouse leave');
}
}, '.demo');
});
</script>
</head>
<body>
<h1>Heading 1</h1>
<div class="demo" id="d1">Demo One</div>
<div class="demo" id="d2">Demo Two</div>
<p>Mouse enter and leave will generate alert boxes.</p>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP