JavaScript 动态更换li背景颜色

  • Post author:
  • Post category:java


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <script type="text/javascript">
        window.onload = function () {
            var myul = document.getElementById("ulme");
            var myli = myul.getElementsByTagName("li");

            for (var j = 0; j < myli.length; j++) {
                //myli[j].style.border = "1px solid #000";
                myli[j].onmouseover=function(){
                    this.style.background = 'blue';
                }
                myli[j].onmouseout = function () {
                    this.style.background = 'white';
                }
            }
            var every=document.getElementById("everywhere");
            every.parentNode.removeChild(every);


        }
    </script>
</head>

<body>
    <ul id="ulme">
        <li id="everywhere">It can be found everywhere.</li>
        <li class="test">It's easy to use.</li>
        <li class="test">It can help you to find what you want,really quickly.</li>
    </ul>

</body>
</html>



版权声明:本文为rowland001原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。