1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <textarea name="" id="txt1" cols="30" rows="10"></textarea> <input type="text" name="" id="txt2"> <input type="button" id="btn1" value="留言">
<script> window.onload = function (){ var oTxt1 = document.getElementById("txt1"); var oTxt2 = document.getElementById("txt2"); var oBtn1 = document.getElementById("btn1"); oTxt2.onkeydown = function (ev){ var oEvent = ev || event; if (oEvent.keyCode === 13 && oEvent.ctrlKey) { oTxt1.value += oTxt2.value + '\n'; oTxt2.value = ""; } } } </script> </body> </html>
|
附上另外两个属性: shiftKey, altKey