在javascript中,我们要常常用到event对象来处理一些事件,但是IE和Firefox下event对象的属性是不同的。

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

相关文章:

  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-24
  • 2022-02-18
  • 2021-09-24
  • 2021-12-13
  • 2022-02-08
  • 2021-08-22
相关资源
相似解决方案