마우스를 움직일 때. 콘솔 말해 : 정의되지 않은 'x'속성을 설정할 수 없습니다 ... 왜 이런 일이? 어떻게 객체 초기화 .... 그런 이벤트 리스너를 할당 할 때 당신은 개체의 컨텍스트를 잃어버린하는JavaScript 초기화 중 "정의되지 않은 x '속성을 설정할 수 없습니다."
<html>
<head>
</head>
<body>
<div id = "div1">
<img id="omna" src="http://online1.map.bdimg.com/tile/?qt=tile&x=0&y=0&z=4&styles=pl&udt=20141102" width="256px" height="256px" unselectable="on" style="position:absolute;user-select:yes;-moz-user-select:yes;-webkit-user-select:;"/>
</div>
<script type="text/javascript">
var kMapControl = {
mousemovepos : {
x:0,
y:0
},
onmousemove : function (ev) {
ev = ev || event;
// here tell me:this.mousemovepos.x is not undefined
this.mousemovepos.x = ev.clientX;
this.mousemovepos.y = ev.clientY;
},
init : function(){
var div = document.getElementById("div1");
div.addEventListener("mousemove", this.onmousemove, false);
}
};
window.onload = function(){
kMapControl.init();
};
</script>
</body>
</html>
'EV = EV || 이벤트;는 W3C 이벤트 모델을 지원하지 않는 브라우저에서만 필요합니다. 이러한 브라우저에는 * addEventListener *가 없으므로 할당에별로 중요하지 않습니다. – RobG