createHsArea: function(obj) {
var area = document.createElement('area');
area.shape = 'poly';
area.coords = obj.coords;
area.href = '#';
area._name = obj.name;
area._id = obj.id;
area._x = obj.x;
area._y = obj.y;
area._xs = obj.xs;
area._ys = obj.ys;
area.onclick = function() {
return false; };
area.onfocus = function() {
this.blur(); };
area.onmousemove = this.area_mousemove.bindAsEventListener(this);
area.onmouseout = this.area_mouseout.bindAsEventListener(this);
this.maphs.appendChild(area); area_mousemove: function(evt) {
var src = evt.srcElement || evt.target;
var ex = evt.clientX;
var ey = evt.clientY;
this.mapAreaInfoTip.style.left = ex + 'px';
this.mapAreaInfoTip.style.top = (ey - 25) + 'px';
if (this.mapAreaInfoTip.style.display == 'none' && src._name != '') {
this.mapAreaInfoTip.innerHTML = src._name;
this.mapAreaInfoTip.style.display = ''; }
}
var strArea = "";
strArea += "<v:polyline style=\"cursor:pointer; POSITION: absolute; filter:alpha(style=1,opacity=0);\" id=polya" + area._id + " points = " + area.coords + " onclick=\"\" onmouseover=\"this.style.filter= '';\" title='" + area._name + "' onmousemove=\"area_mousemove.bindAsEventListener(this);\" onmouseout=\"this.style.filter= 'alpha(style=1,opacity=0) ';\" strokecolor = '#00FF00' strokeweight = '1.2pt'><v:fill opacity = '19660f'></v:fill></v:polyline>";
this.mapArea.innerHTML = strArea;
},
area_mousemove: function(evt) {
var src = evt.srcElement || evt.target;
var ex = evt.clientX;
var ey = evt.clientY;
this.mapAreaInfoTip.style.left = ex + 'px';
this.mapAreaInfoTip.style.top = (ey - 25) + 'px';
if (this.mapAreaInfoTip.style.display == 'none' && src._name != '') {
this.mapAreaInfoTip.innerHTML = src._name;
this.mapAreaInfoTip.style.display = ''; }
}
我想在这里 strArea += "<v:polyline style=\"cursor:pointer; POSITION: absolute; filter:alpha(style=1,opacity=0);\" id=polya" + area._id + " points = " + area.coords + " onclick=\"\" onmouseover=\"this.style.filter= '';\" title='" + area._name + "' onmousemove=\"area_mousemove.bindAsEventListener(this);\" onmouseout=\"this.style.filter= 'alpha(style=1,opacity=0) ';\" strokecolor = '#00FF00' strokeweight = '1.2pt'><v:fill opacity = '19660f'></v:fill></v:polyline>";的 onmousemove里像area这样调用area_mousemove这个方法 area.onmousemove = this.area_mousemove.bindAsEventListener(this); 要怎么调用啊?新手弱弱的问下 js 方法写法不是 function 方法名(){} 这样的吗? area_mousemove: function(evt)这样写需要什么支持吗?
var area = document.createElement('area');
area.shape = 'poly';
area.coords = obj.coords;
area.href = '#';
area._name = obj.name;
area._id = obj.id;
area._x = obj.x;
area._y = obj.y;
area._xs = obj.xs;
area._ys = obj.ys;
area.onclick = function() {
return false; };
area.onfocus = function() {
this.blur(); };
area.onmousemove = this.area_mousemove.bindAsEventListener(this);
area.onmouseout = this.area_mouseout.bindAsEventListener(this);
this.maphs.appendChild(area); area_mousemove: function(evt) {
var src = evt.srcElement || evt.target;
var ex = evt.clientX;
var ey = evt.clientY;
this.mapAreaInfoTip.style.left = ex + 'px';
this.mapAreaInfoTip.style.top = (ey - 25) + 'px';
if (this.mapAreaInfoTip.style.display == 'none' && src._name != '') {
this.mapAreaInfoTip.innerHTML = src._name;
this.mapAreaInfoTip.style.display = ''; }
}
var strArea = "";
strArea += "<v:polyline style=\"cursor:pointer; POSITION: absolute; filter:alpha(style=1,opacity=0);\" id=polya" + area._id + " points = " + area.coords + " onclick=\"\" onmouseover=\"this.style.filter= '';\" title='" + area._name + "' onmousemove=\"area_mousemove.bindAsEventListener(this);\" onmouseout=\"this.style.filter= 'alpha(style=1,opacity=0) ';\" strokecolor = '#00FF00' strokeweight = '1.2pt'><v:fill opacity = '19660f'></v:fill></v:polyline>";
this.mapArea.innerHTML = strArea;
},
area_mousemove: function(evt) {
var src = evt.srcElement || evt.target;
var ex = evt.clientX;
var ey = evt.clientY;
this.mapAreaInfoTip.style.left = ex + 'px';
this.mapAreaInfoTip.style.top = (ey - 25) + 'px';
if (this.mapAreaInfoTip.style.display == 'none' && src._name != '') {
this.mapAreaInfoTip.innerHTML = src._name;
this.mapAreaInfoTip.style.display = ''; }
}
我想在这里 strArea += "<v:polyline style=\"cursor:pointer; POSITION: absolute; filter:alpha(style=1,opacity=0);\" id=polya" + area._id + " points = " + area.coords + " onclick=\"\" onmouseover=\"this.style.filter= '';\" title='" + area._name + "' onmousemove=\"area_mousemove.bindAsEventListener(this);\" onmouseout=\"this.style.filter= 'alpha(style=1,opacity=0) ';\" strokecolor = '#00FF00' strokeweight = '1.2pt'><v:fill opacity = '19660f'></v:fill></v:polyline>";的 onmousemove里像area这样调用area_mousemove这个方法 area.onmousemove = this.area_mousemove.bindAsEventListener(this); 要怎么调用啊?新手弱弱的问下 js 方法写法不是 function 方法名(){} 这样的吗? area_mousemove: function(evt)这样写需要什么支持吗?
name:"name",
say :function(name){alert(name);}
}obj.say(obj.name);
function test(itm){
......
}个人签名:http://hanguangmen.com 旅游信息化建设。
肯定不行啊,最基本的this的指向就完全不同
myobj={
createHaArea:function(obj){...},
area_mousemove:function(evt){...}
};
2.楼主代码中onmousemove=\"area_mousemove.bindAsEventListener(this);\"这句在经过浏览器解析后会变成:
Element.onmousemove=anonymous function(){
area_mousemove.bindAsEventListener(this);
}
很明显,里面的this指向的是当前的网页元素,而不是楼主期望的event对象,会发生错误。
3.可以正常工作的代码经转换后应该是:
Element.onmousemove=anonymous function(){
myobj.area_mousemove(event);
}
转换成楼主的代码就是:onmousemove=\"myobj.area_mousemove(event);\"
那个myobj,是将楼主的js代码包起来的对象名,随便起的。