HTML中使用JS函数通过id调用div,但一直显示()is not a function

<style> body{
     background-color:#B0B0B0     
     }
      .header{
           background-color:#000000;     
           width:100%;     
           height:100px;     
           } 
           #left{
                background-color:#FF0000;     
                width:15%;     
                height:700px;     
                }
                 </style>
                  </head>
                   <body >
                    <div class="header"></div>
                     <div id="left" onmouseover="hidden()"></div>
                      <script>     
                      function hidden(){
                               document.getElementById("left").style.backgroundColor="#FFFFFF";         
                               } </script>
                                </body>
                                 ```Uncaught TypeError: hidden is not a function
                                 onmouseover @ index.html:26


慕码人8056858
浏览 2079回答 1
1回答

跃然一笑

hidden为保留关键字,不能作为变量名。修改变量名即可,&nbsp;<style> body{ &nbsp;&nbsp;&nbsp;&nbsp;background-color:#B0B0B0 &nbsp;&nbsp;&nbsp;&nbsp;} .header{ &nbsp;&nbsp;&nbsp;&nbsp;background-color:#000000; &nbsp;&nbsp;&nbsp;&nbsp;width:100%; &nbsp;&nbsp;&nbsp;&nbsp;height:100px; &nbsp;&nbsp;&nbsp;&nbsp;} #left{ &nbsp;&nbsp;&nbsp;&nbsp;background-color:#FF0000; &nbsp;&nbsp;&nbsp;&nbsp;width:15%; &nbsp;&nbsp;&nbsp;&nbsp;height:700px; &nbsp;&nbsp;&nbsp;&nbsp;} </style> </head> <body&nbsp;> <div&nbsp;class="header"></div> <div&nbsp;id="left"&nbsp;onmouseover="hidden1()"></div> <script> &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;hidden1(){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById("left").style.backgroundColor="#FFFFFF"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} </script> </body>在谷歌调试后结果:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript