会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 452楼
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 453楼
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 454楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 455楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 456楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        /* ul {
            list-style: none;
        }
        li {
            display: inline-block; width: 100px; margin: 10px; text-align: center; background-color: skyblue; height: 30px; line-height: 30px;
        }
        a {
            text-decoration: none;
            color: orangered;
        }*/
        li:hover {
            background-color: palevioletred;
        }
        li:hover a {
            color: #ffffff;
        } 
    </style>
</head>
<body>
    <!-- <ul>
        <li><a href="#">丰田</a></li>
        <li><a href="#">本田</a></li>
        <li><a href="#">雷克萨斯</a></li>
        <li><a href="#">马自达</a></li>
    </ul> -->

    <script>
        var Arr=['丰田','本田','雷克萨斯','马自达','尼桑'];
        var ul=document.createElement('ul');
        var ul_style=document.createAttribute('style');
        ul_style.value='list-style: none;';
        ul.setAttributeNode(ul_style);
        for (var i=0; i<Arr.length; i++) {
            var li=document.createElement('li');
            var li_style=document.createAttribute('style');
            li_style.value='display: inline-block; width: 100px; margin: 10px; \
            text-align: center; background-color: skyblue; height: 30px; line-height: 30px;';
            li.setAttributeNode(li_style);
            var a=document.createElement('a');
            a.innerHTML=Arr[i];
            // var a_text=document.createTextNode(Arr[i]);
            var a_style=document.createAttribute('style');
            a_style.value='text-decoration: none; \
            color: orangered;';
            // a.appendChild(a_text);
            a.setAttributeNode(a_style);
            li.appendChild(a);
            ul.appendChild(li);
        }
        document.body.appendChild(ul);
    </script>
</body>
</html>

老师,我写出来之后,网页上确实显示了,但是hover失效了,而且a标签也没有小手了。

QQ截图20201205142438.png


WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 457楼
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 459楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 460楼
WEB前端全系列/第二阶段:JavaScript编程模块/函数与对象 462楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 464楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637