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

图片.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模型 527楼

<!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编程模块/面向对象编程 528楼
WEB前端全系列/第二阶段:JavaScript编程模块/JavaScript基础与变量 529楼

<script>
var div = document.querySelector("#div");
console.log("网页可见区域宽client" + document.body.clientWidth);
console.log("网页可见区域高client" + document.body.clientHeight);
console.log("网页可见区域宽offset" + document.body.clientWidth);
console.log("网页可见区域高offset" + document.body.clientHeight);
console.log("网页正文全文宽scroll"+document.body.scrollWidth);
console.log("网页正文全文高scroll"+document.body.scrollHeight);
console.log("网页被卷曲的宽scroll"+document.body.scrollLeft);
console.log("网页被卷曲的高scroll"+document.body.scrollTop);
console.log("------------------------------------");
console.log("浏览器宽"+window.outerWidth);
console.log("浏览器高"+window.outerHeight);
console.log("浏览器视口宽(计算滚动条)"+window.innerWidth);
console.log("浏览器视口高(计算滚动条)"+window.innerHeight);
console.log("浏览器视口宽(不计算滚动条)"+document.documentElement.clientWidth);
console.log("浏览器视口高(不计算滚动条)"+document.documentElement.clientHeight);
console.log("返回页面滚动距离X"+window.pageXOffset);
console.log("返回页面滚动距离Y"+window.pageYOffset);
console.log("浏览器距离屏幕X"+window.screenX);
console.log("浏览器距离屏幕Y"+window.screenY);
</script>

在页面中插入一个宽高分别为3000和2000的div,用

document.body.clientHeight

document.body.clientHeight

获取的文档可视区域高度为什么都为2000呢?

image.png

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义右击菜单案例</title>
    <style>
        *{padding: 0;margin: 0}
        ul{
            list-style: none;
            background-color: darkgray;
            min-width: 220px;
            display: inline-block;
            position: absolute;
            display: none;
        }
        ul li{
              height: 30px;
              line-height: 30px;
              padding:5px 20px;
              cursor: pointer;
            transition: 0.3s;

        }
        ul li:hover{
            background-color: olivedrab;
            color: #fff;
        }
    </style>
</head>
<body>
<ul>
    <li>北京尚学堂</li>
    <li>欢迎你</li>
    <li>去百度搜索页面中选中的内容</li>
    <li>赚大钱</li>
</ul>
<textarea cols="80" rows="20"></textarea>
<script>
    var ul=document.querySelector("ul");
    document.oncontextmenu=function (eve) {
        return false;//表示事件禁用
    }
    document.onmouseup=function (eve) {
    //eve.button能够判断鼠标用的是哪个按钮
        //0左键  1滑轮 2邮件
        if (eve.button==2){
         ul.style.display="inline-block";
         //设置鼠标点击的位置
            ul.style.left=eve.clientX+"px";
            ul.style.top=eve.clientY+"px";
        }else {
            //关闭菜单
            ul.style.display="none";
        }
    }
    //点击某一菜单选项时触发的事件(事件委托)
    ul.onmousedown=function (eve) {
     if (eve.target.innerHTML=='北京尚学堂'){
        alert("那就去吧");
     }else if (eve.target.innerHTML=='欢迎你') {
         if (confirm('欢迎你?')) {
             window.close();}
     }else if (eve.target.innerHTML=='去百度搜索页面中选中的内容'){
             var result=document.getSelection().toString();
             window.open('http://www.baidu.com/s?wd='+result);
         }else {
         var result=prompt("输入内容然后去百度");
         window.open('http://www.baidu.com/s?wd='+result);
     }
    }
</script>
</body>
</html>

老师我写的这个怎么不跳转百度?为什么要变成字符串的形式?8.jpg

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

课程分类

百战程序员微信公众号

百战程序员微信小程序

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