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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<div class="div1">
    <div class="div2">
        这是div2
    </div>
    <button>点我</button>
</div>
    <script>
        /*node方法
        1.appendChild()
        node1.appendChild(node2)  将节点2插入在node1最后面
        注意 js创建的节点对象之间没有文本对象
        2、hasChildNodes()  此方法返回一个布尔值  是否有子节点
        3、cloneNode(布尔值) 克隆节点,布尔值如果true 则克隆子节点 如果为flase 则不克隆子节点
          克隆节点不会克隆原节点的事件 但是会复制属性和内容   

        */
     var div1=document.querySelector('.div1');
     var div3=document.createElement('div');
     var div4=document.createElement('div');
     var but=document.querySelector('button');
     div3.innerHTML='lalal';
     div1.appendChild(div3);
     div1.appendChild(div4)
     console.log(div1.childNodes);
     var num=1;
     var str='这是第'+num+'克隆';
     but.onclick=function(){
        var clonebut=but.cloneNode(true);
       clonebut.innerHTML=str;
         div1.appendChild(clonebut);
      num+=1;
         console.log(num);
     }

    </script>
</body>
</html>

老师 这个事件里面的num累加怎恶保存到全局变量num

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

老师好,控制提示框移动范围时,使用“if else”可以实现,但使用“switch”时没有效果。

应该是我的switch语句没写对(第35行代码),怎么写才正确?求指导,谢谢。

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鼠标事件</title>
<style>
    input{
        width: 300px;
        margin: 100px 600px 0px;
    }
    #tips{
        width: 30px;
        height: 25px;
        margin: 0px 750px;
        padding: 0;
        font-size: 18px;
        text-align: center;
        border: 1px solid aqua;
        position: absolute;
        display: none;
    }
</style>
</head>
<body>
    <input type="range" min="0" max="100" value="50">
    <div id="tips"></div>
<script>
    var input=document.querySelector('input');
    var tips=document.getElementById('tips');
    function move(){
        input.onmousemove=function () {
            var x=event.clientX;
            var Y=event.clientY;
            // 使用switch语句控制提示框移动范围????????????????????????????????????????
/*            switch (x) {
                case x<600:tips.style.left=-150+'px';
                    break;
                case x>900:tips.style.left=150+'px';
                    break;
                case x>=600&&x<=900:tips.style.left=(x-750)+'px';
                    break;
            }*/
            // 使用if语句控制提示框移动范围
            if (event.clientX>900){
                x = 900;
            }else if (event.clientX<600){
                x = 600;
            }else{
                tips.style.left=(x-750)+'px';
            }

            tips.innerHTML=input.value;

            // console.log('(x,y):('+x+','+'y'+')');
        }
    };
    input.onmousedown=function () {
        tips.style.display='block'
        move();
    };
    input.onmouseup=function () {
        tips.style.display='none'
        input.onmousemove=null;
    }
</script>
</body>
</html>


WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 517楼
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 521楼
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 522楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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