繁体   English   中英

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

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

共享代码
帮我解决

<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>

我要去哪里错了????

您的代码实际有效。 如果您是指字体颜色,则添加它-(x.style.color =“ blue”;)。 您的语法没有错。 但是,如果带有文件扩展名,则使其为“ .html”。

对不起。 我以前的答案不正确。 您的语法应如下所示:

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

对于文本/字体的颜色:x.style.color =“ blue”;

暂无
暂无

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

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