1.keyCode||which||charCode
IE下支持keyCode,不支持which,charCode。
Firefox下支持keyCode,除功能键外,其他键值始终为0,Firefox下支持which和charCode属性
要获取兼容IE和Firefox的键值,有如下方法:
在函数调用时传递event
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&g t;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Demo</title>
<script type="text/javascript">
function test_event(e){
var e=e||event;
currKey=e.keyCode||e.which||e.charCode;
document.getElementById("key").value = currKey;
}
</script>
</head>
<body>
<input type="text" onkeyup="test_event(event)"/>
<input type="text" ).click(function(event){ alert( event.isImmediatePropagationStopped() ); event.stopImmediatePropagation(); alert( event.isImmediatePropagationStopped() );});
这些函数中 stopPropagation() 是我们最长用的也是一定会用到的函数. 相当于操作原始event对象的event.cancelBubble=true来取消冒泡.
转自:http://hi.baidu.com/happygmq/blog/item/d83f725091b9cc2f42a75baa.html