<!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