是哪里出错了,按钮不起作用

来源:3-3 编程练习

qq_明天_78

2016-09-17 20:17

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style>

*{margin:0;padding:0;}

#div_1{font-size:12px;padding:6px 0 0 10px;}

#div_2{border:1px solid #000;width:300px;height:150px;background:#CCCCCC;position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-75px;display:none;}

#div_2 p{height:20px;font-size:12px;padding:5px 0 0 5px;font-weight:bold;border-bottom:1px solid #000;}

#close{width:14px;height:14px;position:absolute;right:2px;top:2px;font-size:11px;}

</style>

<script>

window.onload=function(){


var divone=document.getElementById('div1');

var divtwo=document.getElementById('div2');

var bt=document.getElementById('bt');

var clo=document.getElementById('close');


function addEvent(ele,type,hander){

if(ele.addEventListener){

ele.addEventListener(type,hander,false);

}

else if(ele.attachEvent){

ele.attachEvent('on'+type,hander);

}

else{

ele['on'+type]=hander;

}

}

function displayA(){

divtwo.style.display='block';

}

function cancel(){

divtwo.style.display='none';

}

addEvent(bt,'click',displayA);

addEvent(clo,'click',cancel);


}

</script>

</head>


<body>

<div id="div_1">

亲,请登录<input type="button" value="登录" id="bt"/>

</div>

<div id="div_2">

<p>用户登录</p><span id="close">关闭</span>

</div>

</body>

</html>


写回答 关注

1回答

  • qq_慕数据9481021
    2016-09-17 21:02:27

    var divone=document.getElementById('div1') 改为div_1;

    var divone=document.getElementById('div2');改为div_2

    qq_明天_...

    恩好了,非常感谢

    2016-09-17 21:20:54

    共 1 条回复 >

DOM事件探秘

DOM事件?本课程会通过实例来给小伙伴们讲解如何使用这些事件

99544 学习 · 1197 问题

查看课程

相似问题