简体   繁体   English

我要改变颜色 <div> 在mouseOver函数上的javascript中。我在哪里出错?

[英]I'm to change color of <div> in javascript on mouseOver function.Where am i going wrong?

sharing the code 共享代码
Help me with the solution 帮我解决

<div id ="hus" onmouseover="mouseOver()" style="background-color:#00FFFF;width:120px;height:20px;padding:40px;"> HUSAIN </div>

    <script>
    function mouseOver() {
      var x = document.getElementById( "hus" );
      x.style.backgroundColor = "red";
    }
    </script>

where am i going wrong???? 我要去哪里错了????

Your codes actually work. 您的代码实际有效。 If you mean the font-color, add this - (x.style.color = "blue";). 如果您是指字体颜色,则添加它-(x.style.color =“ blue”;)。 There's nothing wrong with your syntax. 您的语法没有错。 But if it's with file extension, make it's ".html". 但是,如果带有文件扩展名,则使其为“ .html”。

I'm sorry. 对不起。 My previous answer is incorrect. 我以前的答案不正确。 Your syntax should be like this: 您的语法应如下所示:

For the background: x.style.background = "red"; 对于背景:x.style.background =“ red”;

For the color of the text/font: x.style.color = "blue"; 对于文本/字体的颜色:x.style.color =“ blue”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM