@
cfan365以下代码是按照LZ的判断点击坐标...虽然建一个隐藏div判断是否点击了这个div要更正常些
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<script type="text/javascript">
var bind = function(obj, action, func) {
if (window.addEventListener) {
obj.addEventListener( action, function(event) {
func(obj, event);
}, false);
} else if (window.attachEvent) { //IE
obj.attachEvent('on' +action, function(event) {
func(obj, event);
});
}
}
var callBack = function(obj, event) {
console.info(event);
if (event.clientX < 40 || event.clientX > 120) {
return;
}
if (event.clientY < 120 || event.clientY > 220) {
return;
}
alert('click in box!');
}
</script>
<body style="width:100%;height:100%;">
<div style="border: 1px solid;height: 100px;left: 40px;position: absolute;top: 120px;width: 100px;"></div>
<script type="text/javascript">
bind(document.body, 'click', callBack);
</script>