js中Cannot read property 'style' of undefined


<script>

window.onload=function(){

     var div=document.getElementById('content')

     var btn=div.getElementsByTagName('input')

     var div_d=div.getElementsByTagName('div')

    

     for (var i = 0; i < btn.length; i++) {

         btn[i].onclick=function () {

             for (var i2 = 0; i2 < div_d.length; i2++) {

                 div_d[i2].style.display='none'

             }

             div_d[i].style.display='block'//这行报错

         }

     }

}

</script>



676548736484165813
浏览 1876回答 3
3回答

悟道参禅

 你button的个数和div的个数是一样的?
打开App,查看更多内容
随时随地看视频慕课网APP