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

<!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) 349楼
WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 351楼
WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 352楼

为什么最后一个子标签不是文本,</script>和</body>之间不是有空格吗

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div  class="div1">div1
    <div  id="div2">div2</div>
</div>
<span>这是span标签</span>
<script>
    var div1=document.querySelector('.div1');
    var div2=document.querySelector('#div2');
    var span=document.querySelector('span');
    /*
    1.textContent
    描述:返回当前节点和它的所有后代节点的文本内容。
     var result=document.getElementById('divA').textContent// This is some text
     console.log(result);
     2.nodeValue
     描述:nodeValue属性一般只用于Text节点
     console.log(span.firstChild.nodeValue);
     span.firstChild.nodeValue='新的span值';
     3.childNodes属性
     描述:childNodes属性返回一个节点集合(NodeList),节点集合中包括当前节点的所有子节点
     例子:
     var childList=div1.childNodes;
     console.log(childList);
     console.log(childList.length);
     console.log(childList instanceof  Array);
     console.log(childList[1]);
     4.firstChild/ lastChild
     描述:返回第一个\最后一个子节点,如果不存在返回null
     console.log(div1.firstChild);
     console.log(div1.lastChild);
     */
        console.log(document.body.firstChild);
        console.log(document.body.lastChild);
</script>
</body>
</html>

blob.png

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 360楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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