javascript高手们帮帮忙解决个问题吧

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/... <!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>
</head>
<script language="javascript">
function test(){
this.tname='';
this.$ = function(_id)
{
return document.getElementById(_id);
};
this.closediv=function(){
var tObj1 = this.$('sms');
var tob = this.$('Mask');
tObj1.removeChild(tob);
};
this.indiv=function(){
var tObj1 = this.$('sms');
var tDiv1 = document.createElement('div');
tDiv1.setAttribute('id','Mask');
tDiv1.style.position = 'absolute';
tDiv1.style.top = '0';
tDiv1.style.left = '0';
tDiv1.style.background = '#000000';
tDiv1.style.filter = 'Alpha(Opacity=50)';
tDiv1.style.opacity = '0.5';
tDiv1.style.width = '100px';
tDiv1.style.height = '100px';
tDiv1.style.zIndex = '100';
tObj1.appendChild(tDiv1);
};
this.show=function(){
var mask=this.$("Mask");
//就是这里了.
mask.attachEvent('onclick',this.closediv);//这里了,如何调用this.closediv呢???
}
this.instr=function(val){
this.tname=val;
this.$("sms").innerHTML='fdsfdslfds';
this.indiv();
this.show();
};
}
</script>
<body>
<div id="sms"></div>
<script language="javascript">
var tt = new test();
tt.instr('tt');
</script>
</body>
</html>
要如何修改呢.谢谢
展开
 我来答
wangshiyi95
2009-06-10 · TA获得超过2418个赞
知道大有可为答主
回答量:1709
采纳率:0%
帮助的人:0
展开全部
1.把document type改成 xhtml strict
2.head必须有一个title
3.html只能有head和body子元素,所以请把script放到head里或body里
4.script必须有type属性
5.不要用attachEvent
6.mask.attachEvent('onclick',this.closediv);这样绑定事件的话肯定会出错
var _this=this;
mask.onclick=function(e){
_this.closeDiv();
7.$('Mask')预计返回null
};
百度网友a28217434
2009-06-05 · TA获得超过569个赞
知道小有建树答主
回答量:451
采纳率:0%
帮助的人:353万
展开全部
<!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>
</head>
<script language="javascript">
function test(){
this.tname='';
$ = function(_id)
{
return document.getElementById(_id);
};
this.closediv=function(){

var tObj1 = $('sms');

var tob = $('Mask');
tObj1.removeChild(tob);
};
this.indiv=function(){
var tObj1 = $('sms');
var tDiv1 = document.createElement('div');
tDiv1.setAttribute('id','Mask');
tDiv1.style.position = 'absolute';
tDiv1.style.top = '0';
tDiv1.style.left = '0';
tDiv1.style.background = '#000000';
tDiv1.style.filter = 'Alpha(Opacity=50)';
tDiv1.style.opacity = '0.5';
tDiv1.style.width = '100px';
tDiv1.style.height = '100px';
tDiv1.style.zIndex = '100';
tObj1.appendChild(tDiv1);
};
this.show=function(){
var mask=$("Mask");
//就是这里了.
mask.attachEvent('onclick',this.closediv);//这里了,如何调用this.closediv呢???
}
this.instr=function(val){
this.tname=val;
$("sms").innerHTML='fdsfdslfds';
this.indiv();
this.show();
};
}
</script>
<body>
<div id="sms"></div>
<script language="javascript">
var tt = new test();
tt.instr('tt');
</script>
</body>
</html>

js的this应用是个迷宫!使用需谨慎!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
飞蛋蛋
2009-06-05 · TA获得超过973个赞
知道小有建树答主
回答量:816
采纳率:0%
帮助的人:662万
展开全部
mask.attachEvent('onclick',this.closediv);//这里了,如何调用this.closediv呢???

答案就是,attachEvent这个函数表示你要给某个控件添加事件,
‘onclick’表示你的时间类型是点击鼠标左键
this.closediv:你之前定义过一个一个函数: this.closediv=function(){
var tObj1 = this.$('sms');
var tob = this.$('Mask');
tObj1.removeChild(tob);
};
这个函数对于JS来书相当于一个对象,可以作为参数传达给方法,JS体系里面会自动调用你这个方法,当然参数你不可能有的(你也没有),因为:
attachEvent这个方法已经将你的closediv方法绑定到onclick事件了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式