<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery自定义事件添加触发示例</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button>Button #1</button>
<script>
//1.添加自定义事件
$(document).on("event_mzwu_com", "button", function(event, param1, param2) {
alert(param1 + "\n" + param2);
});
//2.触发自定义事件
$("button").trigger("event_mzwu_com", ["Custom", "Event"]);
</script>
</body>
</html>jQuery自定义事件添加和触发示例
我们可以用jQuery的on方法在任一对象上添加自定义事件,之后用trigger方法触发自定义事件,代码示例:
评论(0)
暂无评论。