js捕获键盘事件firefox和ie有区别
2009-01-15 18:37
656 查看
// 注册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" onkeydown="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);
}
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" onkeydown="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);
}
相关文章推荐
- js 判断键盘事件大全 兼容FireFox和IE(退格、制表、回车、空格、方向键、删除键等)
- .js 兼容 FireFox 和 IE 键盘事件
- 如何用JS获取键盘上任意按键的值?兼容FireFox和IE js获取键盘ASCII码?js键盘事件全面控制
- js 判断键盘事件大全 兼容FireFox和IE(退格、制表、回车、空格、方向键、删除键等)
- 如何用JS获取键盘上任意按键的值?兼容FireFox和IE js获取键盘ASCII码?js键盘事件全面控制
- js键盘事件全面控制 兼容FireFox和IE
- js兼容firefox和ie的ctrl+enter事件捕获
- js 判断键盘事件大全 兼容FireFox和IE(退格、制表、回车、空格、方向键、删除键等)
- js键盘事件全面控制 兼容FireFox和IE
- js 判断键盘事件大全 兼容FireFox和IE(退格、制表、回车、空格、方向键、删除键等)
- js键盘事件全面控制 兼容FireFox和IE
- js 判断键盘事件大全 兼容FireFox和IE(退格、制表、回车、空格、方向键、删除键等)
- JS中的事件绑定,事件捕获,事件冒泡以及事件委托,兼容IE
- JS事件在IE与FF中的区别详细解析
- js捕获键盘事件之keydown、keyup以及keypress
- js监听键盘事件的方法—原生和jquery的区别
- js控制文本框内回车事件--IE and FireFox
- JS中select在firefox与ie之间的区别
- firefox 与 Ie 鼠标事件区别
- IE和Firefox的Js区别