国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JQuery調用綁定click事件的3種寫法

2024-05-06 16:17:46
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了JQuery調用綁定click事件的3種寫法,本文簡潔清晰的給出3種寫法的代碼示例,可以很方便的復制使用,需要的朋友可以參考下

第一種方式:

 

 
  1. $(document).ready(function(){ 
  2. $("#clickme").click(function(){ 
  3. alert("Hello World click"); 
  4. }); 

第二種方式:

 

 
  1. $('#clickmebind').bind("click"function(){ 
  2. alert("Hello World bind"); 
  3. }); 

第三種方式:

 

 
  1. $('#clickmeon').on('click'function(){  
  2. alert("Hello World on");  
  3. });  
  4. });  

注意:第三種方式只適用于jquery 1.7以上的版本

源碼如下:

 

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5.  
  6. <script type="text/javascript" src="js/jquery-1.6.1.min.js"></script> 
  7. <script type="text/javascript" src="js/jquery.validate.js"></script> 
  8. <script type="text/javascript" src="js/jquery.metadata.js"></script> 
  9. <script type="text/javascript" src="js/messages_zh.js"></script> 
  10. <style type="text/css"
  11. #frm label.error { 
  12. color: Red; 
  13. </style> 
  14. </head> 
  15. <script type="text/javascript"
  16.  
  17. $(document).ready(function(){ 
  18. $("#clickme").click(function(){ 
  19. alert("Hello World click"); 
  20. }); 
  21.  
  22.  
  23. $('#clickmebind').bind("click"function(){ 
  24. alert("Hello World bind"); 
  25. }); 
  26.  
  27. $('#clickmeon').on('click'function(){ 
  28. alert("Hello World on"); 
  29. }); 
  30. }); 
  31.  
  32. </script> 
  33. <body> 
  34. <label></label> 
  35. <form id="frm" name="frm" method="post" action=""><label>用 戶 名: 
  36. <input type="text" name="username" id="username" /> 
  37. </label> 
  38. <p> 
  39. <label>郵 編 :<label></label></label> 
  40. <label> 
  41. <input type="text" name="postcode" id="postcode" /> 
  42. <br /> 
  43. </label> 
  44. </p> 
  45. <p><label>數 字 :  
  46. <input type="text" name="number" id="number" /> 
  47. </label> 
  48. <br /><label>身份證號: 
  49. <input type="text" name="identifier" id="identifier" /> 
  50. </label> 
  51.  
  52. <label> 
  53. <input type="button" name="clickme" id="clickme" value="click me" />  
  54. </label> 
  55. <label> 
  56. <input type="button" name="clickmebind" id="clickmebind" value="clickme_bind" /> 
  57. </label> 
  58. <label> 
  59. <input type="button" name="clickmeon" id="clickmeon" value="clickme_on" /> 
  60. </label> 
  61. </p> 
  62. </form> 
  63. </body> 
  64. </html> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 洛宁县| 顺义区| 大化| 鸡泽县| 长宁区| 浮梁县| 塘沽区| 渝中区| 苍山县| 邢台市| 襄汾县| 屏南县| 桂东县| 桐城市| 仙桃市| 普宁市| 长垣县| 绥棱县| 邢台县| 郓城县| 武威市| 江陵县| 买车| 南平市| 巧家县| 交城县| 托克托县| 景泰县| 松原市| 仙游县| 老河口市| 合川市| 高雄市| 天峨县| 延寿县| 英山县| 宣化县| 铜川市| 铁岭市| 丹东市| 两当县|