帮我看看这个js 类,为什么实例化两个对象,相互干扰??
javascriptwindow吧
全部回复
仅看楼主
level 1
Daemon😜 楼主
帮我看看这个js 类,实例化div1和div2,可点击这两个对象,都显示div2的values,这是怎么回事?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


无标题文档

<a href="https://tieba.baidu.com/mo/q/hotMessage?topic_id=0&fid=10519454&topic_name=div1,&is_video_topic=0">#div1,#</a>div2{width:100px; height:100px; background:green}
#div2{background:red}


window.onload=function(){
var div1=document.getElementById("div1")
var div2=document.getElementById("div2")
new Fun(div1,"div1111111")
new Fun(div2,"div22222")
}
function Fun(ojb,values){
_this=this;
this.values=values
this.ojb=ojb;
this.ojb.onclick=function(){
_this.show(_this.values)
}
}
Fun.prototype.show=function(values){
alert(values)
}









2016年06月23日 02点06分 1
level 6
LZ你很有天赋,跟我学做菜吧(咦?)
2016年06月26日 00点06分 2
什么意思?别拿我开玩笑好不好
2016年06月29日 09点06分
1