标签: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="郭菊锋/702004176@qq.com"/> 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>
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>
标签:alt console bsp function onkeydown har onload win javascrip
原文地址:http://www.cnblogs.com/padding1015/p/6797711.html