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

为什么浏览器说'style'这个属性是undefined啊?

为什么浏览器说'style'这个属性是undefined啊?

qq_烟火里的尘埃_0 2016-04-22 17:41:38
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>myTest</title><style>body{margin: 0;padding: 0;}ul{ width: 400px;height: 340px;list-style: none;position: relative;}li{width: 100px;height: 40px;cursor: pointer;float: left;}li:nth-child(1){background: blue;}li:nth-child(2){background: green;}li:nth-child(3){background: yellow;}li:nth-child(4){background: red;}div{width: 400px;height: 300px;display: none;position: absolute;left: 40px;top: 40px;}li:nth-child(1) div{background: blue;display: block;}li:nth-child(2) div{background: green;}li:nth-child(3) div{background: yellow;}li:nth-child(4) div{background: red;}</style><script>window.onload=function(){var oLi = document.getElementsByTagName('li');var oDiv = document.getElementsByTagName('div');for (var i = 0; i < oLi.length; i++) {oLi[i].onclick = function(){oDiv[i].style.display = "block";}}}</script></head><body><ul><li><div></div></li><li><div></div></li><li><div></div></li><li><div></div></li></ul></body></html>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1939 浏览
慕课专栏
更多

添加回答

举报

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