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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>window.name属性</title>
</head>
<body>
<button>跨域传输</button>
<script>
/*    var name = 123;
    console.log(name);
    console.log(typeof name);   //string
    var age = 123;
    console.log(age);
    console.log(typeof age);   //number*/

    //在106page中有定义的var num,想在本页面打印num值
    //如果想要获取一个页面内的信息,那么必须先加载
    var but = document.querySelector('button');
    but.onclick = function () {
        var iframe = document.createElement('iframe');   //创建内联框架(页面中嵌套另个页面)
        iframe.src = 'page.html';    //加载保存了信息的页面(另个页面page.html)
        iframe.style.display = 'none';
        document.body.appendChild(iframe);
        //当iframe加载完毕,意味着window.name的内容已经被赋予完毕
        //page.html中的内容window.name = 'var num = 10;';
        iframe.onload = function (eve) {
            var iframeWindowName = eve.target.contentWindow.name;
            console.log(iframeWindowName);  //打印字符串 var num = 10;
            //将字符串解析为代码
            eval(iframeWindowName);
            console.log(num);    //字符串中的内容 10
        }
    }
</script>
</body>
</html>

其中调用的页面page的代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>page</title>
</head>
<body>
<script>
    window.name = 'var num = 10;';
</script>
</body>
</html>


想问下代码中圈红的内容,是获取的调用页面中整个的内容吗?调用页面中填加script的内容,也可以一起调用吗?还是只调用的body中的内容或者哪个部分的?

图片.png


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

老师好,控制提示框移动范围时,使用“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) 545楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编写带有提示文字的滚动条</title>
    <style>
        div{
            width: 25px;
            height: 25px;
            border: 1px solid;
            line-height: 25px;
            text-align: center;
            position: absolute;
            display: none;
        }
    </style>
</head>
<body>
<input type="range" min="0" max="100" value="5">
<div></div>
<script>
    //获取元素
    var input = document.querySelector('input');
    var div = document.querySelector('div');
    var flag = false;
    //给input填加滑动事件
    input.onmousemove =function () {
        if (flag){
            //获取鼠标移动时坐标
            //console.log('(x,y):('+event.clientX+','+event.clientY+')');
            var divx = input.clientX;
            //当x坐标大于120(移出滚动条时,div隐藏)
            if (divx>120){
                div.style.display='none';
            }
            ////当x坐标小于14(移出滚动条时,div隐藏)
            if (divx<14){
                div.style.display='none';
            }
            else {
                //拖动时div块显示
                div.style.display='block';
            }
            //div的left属性赋值,div跟随上面的移动
            //style后面赋值必须为字符串
            div.style.left=event.clientX-12.5+'px';
            //把input实时的值赋到div块内
            div.innerHTML=input.value;
        }
    };
    //当鼠标按下时,div显示
    input.onmousedown=function () {
        flag=true;
        div.style.display='block';

    };
    //当鼠标抬起时,div隐藏
    input.onmouseup=function () {
        flag=false;
        div.style.display='none';
    }
</script>
</body>
</html>

老师,我想设置在鼠标移出滚动条范围后,鼠标按住时,div块也隐藏掉,但是并没有实现。这个应该如何实现?

图片.png

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 549楼

图片.png

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ppt练习题</title>
</head>
<body>
<!--按图完成效果,要求:
(1)导航静态实现
(2)数据内容动态实现
(3)样式要写在style中,用动态实现。-->
<script>
    var arr = ['全部','精华','分享','问答','招聘'];
    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);
    document.body.appendChild(ul);

    for (var i = 0; i<arr.length ;i++){
        var li = document.createElement('li');
        var li_style = document.createAttribute('style');
        li_style.value = "display: block;float: left;background: azure;margin: 0 5px;width:35px;height: 30px;line-height: 30px;text-align: center;";
        if (i== 0){
            li_style.value ='display: block;float: left;margin: 0 5px;width:35px;height: 30px;line-height: 30px;text-align: center;background:red;';
        }
        li.setAttributeNode(li_style);
        var a = document.createElement('a');
        a.innerHTML = arr[i];
        li.appendChild(a);
        ul.appendChild(li);
    }
</script>
</body>

</html>

老师,这个第一问是这个思路吗?

2、第二问数据内容动态实现是什么思路呢?是用循环和Input结合吗?把input在for循环中创建吗?判断条件的话应该怎么确定,能让他实现动态循环?

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

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>数据解析</title>
</head>
<body>
    <form action="" method="get">
        姓名:<input type="text" name="userName"></br>
        年龄:<input type="text" name="age"></br>
        性别:<input type="text" name="sex"></br>
        <input type="submit">
    </form>
    <button>解析数据</button>
    <script>
        var but=document.querySelector("button");
        function dataParse(outInfo) {
            var obj = {};
            var infoStr = outInfo;
            //先获取?后面的内容
            var realInfo = infoStr.slice(1);
            var proArr = realInfo.split("&");
            for (var i = 0; i < proArr.length; i++) {
                var tempArr = proArr[i].split("=");
                obj[tempArr[0]] = tempArr[1];
            }
            return obj;
        }
        but.onclick=function(){
            var dataObj=dataParse(document.location.search);
            console.log(dataObj);
            }
    </script>
</body>
</html>

老师 我想请问一下,为什么我的也是用英文的,但是在控制台输出的时候却是加密的样子呢?

WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 553楼
WEB前端全系列/第二阶段:JavaScript编程模块/JavaScript基础与变量 554楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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