夺命雷公狗---javascript NO:11 事件对象1

IE模型浏览器下:

事件对象 =  window.event

 

W3C模型浏览器下:

DOM对象.事件 = function(event) {

事件对象 = event;

}

示例代码:

 

<!DOCTYPE html>
<html>
<head>
<meta charset=’utf-8′>
<title></title>
<script src=’public.js’></script>
<script>
window.onload = function(){
$(‘btnok’).onclick = function(event){
//IE模型浏览器
//var event = window.event;
alert(event);
}
}
</script>
</head>
<body>
<input type=’button’ id=’btnok’ value=”点击”>
</body>
</html>

 

 

如何解决兼容性问题

示例:

 

<!DOCTYPE html>
<html>
<head>
<meta charset=’utf-8′>
<title></title>
<script src=’public.js’></script>
<script>
window.onload = function(){
$(‘btnok’).onclick = function(event){
if(window.event){
alert(window.event);
}else{
alert(event);
}
}
}
</script>
</head>
<body>
<input type=’button’ id=’btnok’ value=”点击”>
</body>
</html>

 

posted @ 2015-12-09 09:49  夺命雷公狗  阅读(143)  评论(0编辑  收藏  举报