一、点击事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
document.onclick = function() { //document是最顶层的父节点
alert('a');
}
</script>
</head>
<body>
</body>
</html>
二、事件对象event
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
document.onclick = function(ev) {
//ie
// alert(event.clientX + '--' + event.clientY); //event对象
//ff
// alert(ev.clientX + '--' + ev.clientY);
// alert(ev);
// if (ev) {
// alert(ev.clientX + '--' + ev.clientY);
// } else {
// alert(event.clientX + '--' + event.clientY);
// }
var oEvent = ev || event;
alert(oEvent.clientX + '--' + oEvent.clientY); //clientX clientY页面可视区的坐标
}
</script>
</head>
<body>
</body>
</html>