// 注册onKeyDown事件
var pressedKey;
var keyInfo;
window.onload = function() {
document.getElementById("sql").onkeydown = register;
}
function register(e) {
if (!e) {
e = window.event;
}
if (document.all){
pressedKey = e.keyCode;
} else{
pressedKey = e.which;
}
keyInfo = String.fromCharCode(pressedKey).toLowerCase()
+ "/npressedKey:/t" + pressedKey
+ "/nshiftKey:/t" + e.shiftKey
+ "/nctrlKey:/t" + e.ctrlKey
+ "/naltKey:/t" + e.altKey;
alert(keyInfo);
}
<div id="sql" οnkeydοwn="test(event)" contenteditable="true" style="width: 300px; height: 100px; border-width:1px; border-color:#A7A6AA; border-style:solid; font-style: italic; font-weight: normal; color:#A7A6AA;">
asdf<font color='red'>fdfdfd</font><br/>kjli
</div>
function test(event) {
alert(event.which);
}