JS-製作留言提交系統(支援ctrl+斷行符號)

來源:互聯網
上載者:User

標籤:alt   console   bsp   function   onkeydown   har   onload   win   javascrip   

彈出索引值說明:

//console.log(ev.keyCode)
//斷行符號:13
//ctrl:17

 1 <!DOCTYPE html> 2 <html> 3     <head> 4         <meta charset="UTF-8"> 5         <title>留言提交系統</title> 6         <meta name="author" content="郭菊鋒/[email protected]"/> 7     </head> 8  9     <body>10         <input type="text" name="" id="txt" value="" />11         <input type="button" name="" id="btn" value="提交" /><br />12         <textarea name="" rows="20" cols="80" id="txtArea"></textarea><br />13     </body>14 </html>
html代碼
 1 <script type="text/javascript"> 2     window.onload = function() { 3         var oTxt = document.getElementById("txt"); 4         var oBtn = document.getElementById("btn"); 5         var oTxtArea = document.getElementById("txtArea"); 6         oBtn.onclick = function() { 7             addTxt(); 8         }; 9         oTxt.onkeydown = function(ev) {10             var ev = ev || window.event;11             //console.log(ev.keyCode)12             if(ev.keyCode == 13 && ev.keyCode == 17) {13                 addTxt();14             }15             if(ev.keyCode == 13) {16                 addTxt();17             }18         };19 20         function addTxt() {21             if(oTxt.value == "") {22                 alert("請輸入內容");23             }24             oTxtArea.value = oTxt.value;25             oTxt.value = "";26         };27     }28 </script>
js

 

JS-製作留言提交系統(支援ctrl+斷行符號)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.