demo.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> *{margin:0;padding:0;} body { font-size: 13px; line-height: 130%; padding: 60px; } p {width:200px;background:#888;color:white;height:16px;} </style> <script src="js/jquery-1.10.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('#btn').bind("click", function(){ $('#test').append("<p>我的绑定函数1</p>"); }).bind("click", function(){ $('#test').append("<p>我的绑定函数2</p>"); }).bind("click", function(){ $('#test').append("<p>我的绑定函数3</p>"); }); }) </script> </head> <body> <button id="btn">点击我</button> <div id="test"></div> </body> </html>
效果图:
demo2.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%; padding: 60px; } p { width: 200px; background: #888; color: white; height: 16px; } </style> <script src="js/jquery-1.10.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('#btn').bind("click", function(){ $('#test').append("<p>我的绑定函数1</p>"); }).bind("click", function(){ $('#test').append("<p>我的绑定函数2</p>"); }).bind("click", function(){ $('#test').append("<p>我的绑定函数3</p>"); }); $('#delAll').click(function(){ $('#btn').unbind("click"); }); }) </script> </head> <body> <button id="btn">点击我</button> <div id="test"></div> <button id="delAll">删除所有事件</button> </body> </html>
效果图:
demo3.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%; padding: 60px; } p { width: 200px; background: #888; color: white; height: 16px; } </style> <script src="js/jquery-1.10.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('#btn').bind("click", myFun1 = function(){ $('#test').append("<p>我的绑定函数1</p>"); }).bind("click", myFun2 = function(){ $('#test').append("<p>我的绑定函数2</p>"); }).bind("click", myFun3 = function(){ $('#test').append("<p>我的绑定函数3</p>"); }); $('#delTwo').click(function(){ $('#btn').unbind("click",myFun2); }); }) </script> </head> <body> <button id="btn">点击我</button> <div id="test"></div> <button id="delTwo">删除第二个事件</button> </body> </html>
效果图:
demo4.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%; padding: 60px; } p { width: 200px; background: #888; color: white; height: 16px; } </style> <script src="js/jquery-1.10.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('#btn').one("click", function(){ $('#test').append("<p>我的绑定函数1</p>"); }).one("click", function(){ $('#test').append("<p>我的绑定函数2</p>"); }).one("click", function(){ $('#test').append("<p>我的绑定函数3</p>"); }); }) </script> </head> <body> <button id="btn">点击我</button> <div id="test"></div> </body> </html>
效果图: