为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这段代码是先执行alert("i'm "+this.className);求指导,谢谢

为什么这段代码是先执行alert("i'm "+this.className);求指导,谢谢

为什么这段代码是先执行alert("i'm "+this.className);再执行this.style.backgroundColor="yellow";我想要的效果是先背景改变,再跳出alert,点确认后又变回原来的背景,求指导,谢谢<!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" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <style>  *{   padding: 0;   margin: 0;  }  .id1  {    position: absolute;   background-color: red;   width: 200px;   height: 200px;   z-index: -1;     }  .id2  {   position: absolute;   background-color: blue;   width: 150px;   height: 150px;   top: 25px;   left: 25px;  }  .id3  {   position: absolute;   background-color: green;   width: 100px;   height: 100px;   top: 25px;   left: 25px;  } </style> <script>  function lightHight() {   this.style.backgroundColor="yellow";   alert("i'm "+this.className);   this.style.backgroundColor="";      // body...  }  window.onload=function(){   var divs=document.getElementsByTagName("div");   divs[0].addEventListener("click",lightHight);   divs[1].addEventListener("click",lightHight);   divs[2].addEventListener("click",lightHight);  } </script></head><body> <div>    <div>      <div>       </div>  </div> </div></body></html>
查看完整描述

2 回答

?
lkepanda

TA贡献1条经验 获得超0个赞

我也是背景颜色出不来

查看完整回答
反对 回复 2017-07-16
?
guoyou

TA贡献28条经验 获得超30个赞

效果确实是先背景改变,再跳出alert,点确认后又变回原来的背景   并没有问题

查看完整回答
反对 回复 2017-03-05
  • 慕粉3834220
    慕粉3834220
    我在chrome就无法实现,但是在ie中就可以实现,是有兼容性问题吗
  • 2 回答
  • 0 关注
  • 1797 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信