会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132647个问题
WEB前端全系列/第二阶段:JavaScript编程模块/JavaScript基础与变量 346楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>横向布局的导航栏</title>
</head>
<!--<style>
    ul{list-style: none;padding: 0;margin: 0;}
    ul li{display:inline-block; width:100px; height:100px;line-height:30px;text-align:center; background-color:skyblue;}
    li a{text-decoration: none;color: white;}
    li:hover{background-color: red;}
    li:hover a{color: greenyellow;}
</style>-->
<style>
    li:hover{background-color: red}
    li:hover a{color: greenyellow}
</style>
<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=['首页','军事','娱乐','新闻',];
    //创建ul标签
    var ul=document.createElement('ul');
    var ul_style=document.createAttribute('style');
    ul_style.value='list-style: none;padding: 0;margin: 0;';
    ul.setAttributeNode(ul_style);

      //创建li标签
        for(var i=0;i<4;i++){
            var li=document.createElement('li');
            var li_style=document.createAttribute('style');
            li_style.value='display:inline-block; width:100px; height:100px;line-height:30px;text-align:center;/ background-color:skyblue;';
            li.setAttributeNode(li_style);
            ul.appendChild(li);

      //创建a标签

            var a=document.createElement('a');
            var a_style=document.createAttribute('style');
            a_style.value='text-decoration: none;color: white;';
            a.setAttributeNode(a_style);
            li.appendChild(a);
            a.innerHTML=arr[i];

        }
  document.body.appendChild(ul);

</script>
</body>
</html>
哪里的问题,我的不显示出来


WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 348楼
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 351楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>带有提示文字的滚动条</title>
    <style>
        div{
            width:30px;
            height:15px;
            border: 1px solid black;
            line-height: 15px;
            align:center;
            position:absolute;
            display:none;
        }
    </style>
</head>
<body>
<input type="range" min="0" max="100" value="0"/>  <!--value是当前值-->
<div></div>
<script>
    var div=document.querySelector("div");
    var input=document.querySelector("input");
    var flag=false;
    input.onmousemove=function(){
        div.innerHTML=input.value;
        if(flag) {
            //console.log("(x,y)的值为(" + event.clientX + "," + event.clientY + ")");

            if (event.clientX > 134) {event.clientX = 134;}
            if (event.clientX < 14) {event.clientX = 14;}
            div.style.left = event.clientX + 'px';//style对象的属性值都是字符串,单位包括在字符串中。所以这里用连接符,连接一个字符,使其变成字符串。
            div.style.display = 'block';
        }
    }
    input.onmousedown=function(){//鼠标按下时触发
        flag=true;
        div.style.display='none';
    }
    input.onmouseup=function(){//鼠标抬起时触发
        flag=false;
        div.style.display='none';
    }
</script>
</body>
</html>

我这个绝对定位,距离左边距离的这个功能不能实现。div到第一个位置停止了,但我的程序出来效果图div还可以继续移动

blob.png

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 353楼
WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 355楼
WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 356楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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