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

首頁 > 語言 > JavaScript > 正文

jquery實現Ctrl+Enter提交表單的方法

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

這篇文章主要介紹了jquery實現Ctrl+Enter提交表單的方法,涉及jquery針對鍵盤按鍵的響應與表單操作相關技巧,非常簡單實用,需要的朋友可以參考下

本文實例講述了jquery實現Ctrl+Enter提交表單的方法。分享給大家供大家參考。具體如下:

 

 
  1. <!DOCTYPE HTML>  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8">  
  5. <title>Text Box Enter</title>  
  6. <style type="text/css" media="screen">  
  7. body { 
  8. font: 16px/1.5 helvetica-neue, helvetica, arial, san-serif; 
  9. textarea { 
  10. border: 1px solid #ccc; 
  11. display: block; 
  12. width: 250px; 
  13. height: 100px; 
  14. p { 
  15. border: 1px solid #ccc; 
  16. background: #ececec; 
  17. padding: 10px; 
  18. margin: 10px 0; 
  19. width: 230px; 
  20. button { 
  21. border: 1px solid #ccc; 
  22. background: #ececec; 
  23. -webkit-border-radius: 3px; 
  24. -moz-border-radius: 3px; 
  25. margin-top: 10px; 
  26. padding: 5px 20px; 
  27. </style>  
  28. </head>  
  29. <body>  
  30. <textarea name="msg" id="msg" placeholder="Your Message" autofocus="true"></textarea>  
  31. <button type="submit">Post</button>  
  32. <script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>  
  33. <script type="text/javascript" charset="utf-8">  
  34. $.fn.ctrlEnter = function (btns, fn) { 
  35. var thiz = $(this); 
  36. btns = $(btns); 
  37. function performAction (e) { 
  38. fn.call(thiz, e); 
  39. }; 
  40. thiz.bind("keydown"function (e) { 
  41. if (e.keyCode === 13 && e.ctrlKey) { 
  42. performAction(e); 
  43. e.preventDefault(); 
  44. }); 
  45. btns.bind("click", performAction); 
  46. $("#msg").ctrlEnter("button"function () { 
  47. $("<p class='post'></p>").append(this.val().replace(//n/g, "<br/>")).fadeIn('slow').prependTo(document.body); 
  48. this.val(""); 
  49. }); 
  50. </script>  
  51. </body>  
  52. </html> 

希望本文所述對大家的jquery程序設計有所幫助。

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

圖片精選

主站蜘蛛池模板: 闻喜县| 佛坪县| 祥云县| 虹口区| 长春市| 闸北区| 越西县| 德化县| 甘南县| 龙井市| 晋宁县| 浮梁县| 台江县| 山丹县| 建昌县| 探索| 通化县| 开化县| 宜州市| 佛冈县| 临高县| 陆川县| 巨野县| 朔州市| 白城市| 井研县| 赫章县| 博乐市| 齐河县| 舟曲县| 清远市| 贺兰县| 句容市| 清水县| 邛崃市| 澄江县| 新兴县| 图木舒克市| 洛川县| 砚山县| 资源县|