Blogger Information
Blog 250
fans 3
comment 0
visits 322890
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS-事件对象
梁凯达的博客
Original
731 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		#box{width:200px;height:200px;background:pink;margin:30px;}
		#div1{width:200px;height:200px;background:lightgreen;margin:30px;}
	</style>
</head>
<body>
	<div id="box" onclick="test(event,this)"></div>
	<div id="div1"></div>
</body>
<script>
//标签引入的方式绑定事件对象  获取事件对象 需要在绑定事件的时候传递一个实参为event对象 函数使用一个形参来接受即可
function test(e,obj){
	//alert(e);
	document.title="X:"+e.clientX+"Y:"+e.clientY;
	//alert(obj);
	obj.innerHTML = '男神一样的***---帅想想';
}

//标签绑定
var  div1 = document.getElementById('div1');
div1.onclick=function(e){
	//iE可以直接使用事件对象event 这个对象
	//alert(event);
	//alert(e);
	//解决兼容性问题
	// if(e == undefined){
	// 	//IE
	// 	e = event;
	// }
	// 调整兼容性问题
	var  e = e || event;
	//alert(e);
	document.title="X:"+e.clientX+'Y:'+e.clientY;
	//div1.innerHTML = '狗哥是个大帅哥';
	this.innerHTML = '琦琦是个大美女';

}


</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post