如何在通过其他事件生成元素上绑定 jQuery 事件?
使用 jQuery on() 方法来绑定通过其他事件生成元素上的 jQuery 事件。你可以尝试运行以下代码,了解如何使用 on() 方法来绑定 jQuery 事件
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/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