朋友,要明白在this实际指向谁.
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css" rel="sheetstyle" />
*{padding:0px;margin:0px;}
img{border:0px;}
ul{list-style:none;}
body{
text-align:center;
font-size:12px;
color:#222;
}
a:link,a:visited{text-decoration:none;color:#000;}
a:hover,a:active{text-decoration:underline;color:#8b0000;}
.bodyer{
width:840px;height:586px;
position:relative;
border-left:2px #8b0000 solid;
border-right:2px #8b0000 solid;
overflow:hidden;
margin:0px auto;
}
.button{
width:20px;height:60px;
background:#8b0000;
position:absolute;left:800px;top:40px;
padding:12px 8px;
line-height:30px;
color:#fff;
font-size:14px;
font-weight:bolder;
cursor:pointer;
}
</style>
<script language="javascript" type="text/javascript">
var DIYViewBox=function(TitleObjId,ContObjId,ContObjH,ContObjW,ContObjL,ContObjT)
{
this.ContOldH=ContObjH;
this.ContOldW=ContObjW;
this.ContNewH=0;
this.ContNewW=0;
this.ContOldL=ContObjL;
this.ContOldT=ContObjT;
this.ContNewL=0;
this.ContNewT=0;
this.TitleObj=null;
this.ContObj=null;
this.ISIE=document.all?true:false
_self = this;
function GetObj(ObjName)
{
if(typeof(ObjName)=="string")
{
if(document.getElementById){return document.getElementById(ObjName)}
else{return document.all.ObjName}
}
else
{
return ObjName
}
}
this.AddEvent=function(EventParent,EventType,EventFun)
{
if(GetObj(EventParent).attachEvent)
{GetObj(EventParent).attachEvent("on"+EventType,EventFun)}
if(GetObj(EventParent).addEventListener)
{GetObj(EventParent).addEventListener(EventType,EventFun,false)}
}
this.RemoveEvent=function(EventParent,EventType,EventFun)
{
if(GetObj(EventParent).detachEvent)
{GetObj(EventParent).detachEvent("on"+EventType,EventFun)}
if(GetObj(EventParent).removeEventListener)
{GetObj(EventParent).removeEventListener(EventType,EventFun,false)}
}
this.CreateBox=function()
{
this.TitleObj=GetObj(TitleObjId)
var ParentObj=this.TitleObj.parentNode;
var CreateObj=document.createElement("div");
CreateObj.id=ContObjId;
CreateObj.setAttribute("id",ContObjId)
ParentObj.appendChild(CreateObj)
this.ContObj=GetObj(ContObjId)
this.ContObj.style.position="absolute";
this.ContObj.style.display="block";
this.ContObj.style.height=this.ISIE?this.ContOldH:this.ContOldH+"px";
this.ContObj.style.width=this.ISIE?this.ContOldW:this.ContOldW+"px";
this.ContObj.style.left=this.ISIE?this.ContOldL:this.ContOldL+"px";
this.ContObj.style.top=this.ISIE?this.ContOldT:this.ContOldT+"px";
this.ContObj.style.border="#000 solid 1px"
this.ContObj.innerHTML="danica"
//alert()
this.AddEvent(this.TitleObj,"click",this.ViewBox)
}
this.ViewBox=function()
{
var DIS=(_self.ContObj.style.display="block")?true:false
if(DIS){_self.ContObj.style.display="none"}
else{_self.ContObj.style.display="display"}
}
}
</script>
</head>
<body>
<div class="bodyer">
<div class="button" id="Title">日记</div>
<script language="javascript" type="text/javascript">
Box1=new DIYViewBox("Title","Cont",400,400,20,40);
Box1.CreateBox();
</script>
</div>
</body>
</html>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css" rel="sheetstyle" />
*{padding:0px;margin:0px;}
img{border:0px;}
ul{list-style:none;}
body{
text-align:center;
font-size:12px;
color:#222;
}
a:link,a:visited{text-decoration:none;color:#000;}
a:hover,a:active{text-decoration:underline;color:#8b0000;}
.bodyer{
width:840px;height:586px;
position:relative;
border-left:2px #8b0000 solid;
border-right:2px #8b0000 solid;
overflow:hidden;
margin:0px auto;
}
.button{
width:20px;height:60px;
background:#8b0000;
position:absolute;left:800px;top:40px;
padding:12px 8px;
line-height:30px;
color:#fff;
font-size:14px;
font-weight:bolder;
cursor:pointer;
}
</style>
<script language="javascript" type="text/javascript">
var DIYViewBox=function(TitleObjId,ContObjId,ContObjH,ContObjW,ContObjL,ContObjT)
{
this.ContOldH=ContObjH;
this.ContOldW=ContObjW;
this.ContNewH=0;
this.ContNewW=0;
this.ContOldL=ContObjL;
this.ContOldT=ContObjT;
this.ContNewL=0;
this.ContNewT=0;
this.TitleObj=null;
this.ContObj=null;
this.ISIE=document.all?true:false
_self = this;
function GetObj(ObjName)
{
if(typeof(ObjName)=="string")
{
if(document.getElementById){return document.getElementById(ObjName)}
else{return document.all.ObjName}
}
else
{
return ObjName
}
}
this.AddEvent=function(EventParent,EventType,EventFun)
{
if(GetObj(EventParent).attachEvent)
{GetObj(EventParent).attachEvent("on"+EventType,EventFun)}
if(GetObj(EventParent).addEventListener)
{GetObj(EventParent).addEventListener(EventType,EventFun,false)}
}
this.RemoveEvent=function(EventParent,EventType,EventFun)
{
if(GetObj(EventParent).detachEvent)
{GetObj(EventParent).detachEvent("on"+EventType,EventFun)}
if(GetObj(EventParent).removeEventListener)
{GetObj(EventParent).removeEventListener(EventType,EventFun,false)}
}
this.CreateBox=function()
{
this.TitleObj=GetObj(TitleObjId)
var ParentObj=this.TitleObj.parentNode;
var CreateObj=document.createElement("div");
CreateObj.id=ContObjId;
CreateObj.setAttribute("id",ContObjId)
ParentObj.appendChild(CreateObj)
this.ContObj=GetObj(ContObjId)
this.ContObj.style.position="absolute";
this.ContObj.style.display="block";
this.ContObj.style.height=this.ISIE?this.ContOldH:this.ContOldH+"px";
this.ContObj.style.width=this.ISIE?this.ContOldW:this.ContOldW+"px";
this.ContObj.style.left=this.ISIE?this.ContOldL:this.ContOldL+"px";
this.ContObj.style.top=this.ISIE?this.ContOldT:this.ContOldT+"px";
this.ContObj.style.border="#000 solid 1px"
this.ContObj.innerHTML="danica"
//alert()
this.AddEvent(this.TitleObj,"click",this.ViewBox)
}
this.ViewBox=function()
{
var DIS=(_self.ContObj.style.display="block")?true:false
if(DIS){_self.ContObj.style.display="none"}
else{_self.ContObj.style.display="display"}
}
}
</script>
</head>
<body>
<div class="bodyer">
<div class="button" id="Title">日记</div>
<script language="javascript" type="text/javascript">
Box1=new DIYViewBox("Title","Cont",400,400,20,40);
Box1.CreateBox();
</script>
</div>
</body>
</html>
解决方案 »
- js求带小数的和
- jquery 代码
- javascript能否改变iframe的frameborder属性的值
- 数组问题!
- js在firefox下如何控制realplayer
- 原代码不变的情况下,如何去掉,符号
- JS return undefined 问题
- 如何取得本地时间与UTC时间的时间之差??
- 100分!!!!急!!!!!在线!!!!请问.怎样将一个页面元素对象传递到js文件中
- 这么简单的问题怎么都搞不定?关于checkbox的问题。
- JS表单验证如何用正则表达式判断??
- 请教 <input type="file" id=“...”/> 在前台怎么用赋值的方式给它指定文件路径?? 在线等。。。
http://topic.csdn.net/u/20081104/08/55e3c0fe-711e-406e-bb56-9deecd91cac9.html
http://www.cn-cuckoo.com/wordpress/wp-content/uploads/2007/08/JavaScriptClosures.html#clScCh