会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132647个问题

老师好,控制提示框移动范围时,使用“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) 499楼
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 503楼
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 504楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>window对象的name属性</title>
</head>
<body>
    <button>跨域传输</button>
    <script>
/*         var name=123;
        console.log(name);
        console.log(typeof name);
        var age=123;
        console.log(age);
        console.log(typeof age); */

/*         window.name
        描述:是页面在切换之后,甚至域名更改之后会储存信息的容器
        说明:借助window.name可以实现页面之间数据的传递,称为跨域传输。 */
        //console.log(num);
        //如果想要获取一个页面的信息,那么必须先加载
        var but=document.querySelector('button');
        but.onclick=function(){
            var iframe=document.createElement('iframe');
            iframe.src='page.html';//加载保存了信息的页面
            iframe.style.display='none';
            document.body.appendChild(iframe);
            //当iframe加载完成,意味着window.name的内容已经被赋予完成
            iframe.onload=function(eve){
                var iframeWindowName=eve.target.contentWindow.name;
                //console.log(iframeWindowName);
                eval(iframeWindowName);
                console.log(num);

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

image.png老师为什么这一行在vscode里运行会报错误呢?在WebStorm 就可以运行!!

image.png

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

老师 原型的本身是类??

<!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>
    <script>
        /*            
          描述:原型prototype是js为函数提供的一个对象型属性
              说明:向原型中添加的方法和属性能能够被类的对象共同拥有
               本质:原型的存在是给类的对象添加公有属性
              当访问的属性没有在类的对象中没找到,到Car的原型找
              作用:节约内存空间,让类的对象享有这个属性



              原型的属性
              1.constructor  构造器  指向类的本身
              2._proto_   指向原型本身,提供给本类创建的对象使用
        */
        function Car(){}
        Car.prototype.lun1="左前轮";
        var car1=new Car();
        console.log(car1.lun1);

        function People(hobby){
            //私有属性
            var secret='梦';
           
            // 特权函数,利用闭包实现;读取私有属性
            this.getSecret=function(){
                return secret
            }
            // 公共属性,每个类得对象共同拥有,但属性值不一样;
            this.hobby=hobby;
        }
        //每个类的对象共有的属性,且属性值一样,放在原型上,节省内存空间
        People.prototype.eyes=2
        function CarOne(){

        }
        console.log(CarOne.prototype);
        var CarOne1=new CarOne();
        console.log(CarOne1.__proto__);

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

image.png

WEB前端全系列/第二阶段:JavaScript编程模块/正则对象 510楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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