CodeDescriptionExamplebind(eventType,data,handler)||bind(eventMap)bind function to the elementexample1unbind(eventType,listener)||unbind(event) one(eventType,data,listener)only onceexample1live(eventType,data,handler)bind function to the elementexample1die(eventType,listener) example1 type 1:one function. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>I like that</title> <script type="text/javascript" src="scripts/jquery-1.4.js"></script> <script> $(function(){ $('input').one('click',function(event){ $("<input type='button' id='btn"+($('<input>').size()+10)+"' value='btn"+($('<input>').size()+10)+"'/>").appendTo('body'); }); }) </script> </head> <body> <input type='button' id='btnOK' value='btnOK' /> <input type='button' id='btnOK1' value='btnOK1'/> <input type='button' id='btnOK2' value='btnOK2'/> </body> <html>
type 2:bind function. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>I like that</title> <script type="text/javascript" src="scripts/jquery-1.4.js"></script> <script> $(function(){ $('input').bind('click',function(event){ $("<input type='button' id='btn"+($('<input>').size()+10)+"' value='btn"+($('<input>').size()+10)+"'/>").appendTo('body'); }); }) </script> </head> <body> <input type='button' id='btnOK' value='btnOK' /> <input type='button' id='btnOK1' value='btnOK1'/> <input type='button' id='btnOK2' value='btnOK2'/> </body> <html> type 3:live function. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>I like that</title> <script type="text/javascript" src="scripts/jquery-1.4.js"></script> <script> $(function(){ $('input').live('click',function(event){ $("<input type='button' id='btn"+($('<input>').size()+10)+"' value='btn"+($('<input>').size()+10)+"'/>").appendTo('body'); }); }) </script> </head> <body> <input type='button' id='btnOK' value='btnOK' /> <input type='button' id='btnOK1' value='btnOK1'/> <input type='button' id='btnOK2' value='btnOK2'/> </body> <html>
Type 1 ,when you click the btn1,btn2 btn3 button each once,there will be a new button.but if you click them again,it won't. Type 2 ,when you click the btn1,btn2 btn3 button ,there will be a new button,and you can create the buttons as many as you like,but you can't create a button via the created button. Type 3 ,when you click the btn1,btn2 btn3 button ,there will be a new button,and you can create the buttons as many as you like,and you can create a button via the created button as many as you like.
转载于:https://www.cnblogs.com/Xuhaiyang/archive/2012/07/12/2588435.html
