<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自定義事件</title>
<style type="text/css">
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function(){
? ? ? //自定義事件只能使用bind的方式進行綁定
? ? ? //通過trigger來觸發(fā)
? ? ? $('#btn1').bind('hello',function () {
? ? ? ?? alert('hello!');
});
? ? ? $('#btn2').click(function () {
? ? ? ?? $('#btn1').trigger('hello');
});//點擊按鈕2時'hello'會被trigg觸發(fā)
? ? ? $('#btn1').trigger('hello');
}) //直接觸發(fā)
</script>
</head>
<body>
<input type="button" value="按鈕" id="btn1">
<input type="button" value="按鈕" id="btn2">
</body>
</html>