JavaScript 动态更换li背景颜色

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/rowland001/article/details/50801298
<!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].οnmοuseοver=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>
展开阅读全文

没有更多推荐了,返回首页