会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132578个问题
JAVA 全系列/(隐藏)第二十三阶段:数字货币交易所项目/服务中台_会员系统的开发 26553楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 26555楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    li{background-color: skyblue}
    li:hover{
        background-color: #ff6700;
    }
</style>
<body>
    <button id="button1">获取元素</button>
    <button id="button2">设置元素</button>
    <button id="button3">删除元素</button>

<script>
    var div1=document.createElement('div');
    div1.style.cssText='width:100%;position:relative;background:red;';
    var div2=document.createElement('div');
    div2.style.cssText='width:80%;position: absolute;left: 50%;transform: translateX(-50%)';
    document.body.appendChild(div1);
    var arr=['首页','军事','科技','新闻','游戏'];
    var ul=document.createElement('ul');
    ul.style.cssText='margin:0;padding:0;list-style;text-align: center;background:pink;';
    for (var i=0;i<arr.length;i++){
        var li=document.createElement('li');
        li.style.cssText='display: inline-block;  width: 100px;height: 30px;  line-height: 30px;\
                        text-align: center;  margin-left:5px';
        var a=document.createElement('a');
        a.style.cssText=' text-decoration: none;color: white;';
        a.innerHTML=arr[i];
        li.appendChild(a);
        ul.appendChild(li);
    }
    div2.appendChild(ul);
    div1.appendChild(div2);
    document.body.appendChild(div1);

    var button=document.querySelector('div');
    document.querySelector('#button1').onclick=function () {
       console.log( button.getAttribute('style'));
    };
    document.querySelector('#button2').onclick=function () {
        button.setAttribute('style','display:none');
    };
    document.querySelector('#button3').onclick=function () {
        button.removeAttribute('style');
    }
</script>

</body>
</html>

老师为啥我div1颜色设置不出来

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 26556楼
JAVA 全系列/第一阶段:JAVA 快速入门/控制语句、方法、递归算法 26558楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 26559楼
JAVA 全系列/第八阶段:Linux入门到实战/Linux(旧) 26560楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/商城官网项目 26562楼
Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 26563楼
WEB前端全系列/第五阶段:前后端交互/PHP、数据库编程与设计 26564楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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