Crtl+Enter提交留言

Crtl+Enter提交留言代码:

View Code
 1 <script>
 2 window.onload=function()
 3 {
 4     var oTxt1=document.getElementById('txt1');
 5     var oTxt2=document.getElementById('txt2');
 6 
 7     oTxt1.onkeydown=function(ev)
 8     {
 9         var oEvent=ev||event;
10         if(oEvent.keyCode==13 && oEvent.ctrlKey)
11         {
12             oTxt2.value+=oTxt1.value+'\n';
13             oTxt1.value='';
14          }
15     };
16 };
17 </script>

 

完整代码:

 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=utf-8" />
 5 <title>提交留言</title>
 6 <script>
 7 window.onload=function()
 8 {
 9     var oTxt1=document.getElementById('txt1');
10     var oTxt2=document.getElementById('txt2');
11     
12     oTxt1.onkeydown=function(ev)
13     {
14         var oEvent=ev||event;
15         if(oEvent.keyCode==13 && oEvent.ctrlKey)  //keyCode==13就是等于按回车键
16         {
17             oTxt2.value+=oTxt1.value+'\n';
18             oTxt1.value='';
19         }
20     };
21 };
22 </script>
23 </head>
24 
25 <body>
26 <input type="text" id="txt1" /><br /><br />
27 <textarea id="txt2" cols="40" rows="10"></textarea>
28 </body>
29 </html>

 

posted @ 2013-03-28 11:29  yexingwen  阅读(346)  评论(0编辑  收藏  举报