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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
        }
        
        .zz {
            height: 100%;
            width: 100%;
            display: none;
            position: absolute;
            left: 0;
            top: 0;
            background-color: rgba(0, 0, 0, 0.6);
        }
        
        .box {
            height: 290px;
            width: 700px;
            position: absolute;
            left: 50%;
            display: none;
            top: 50%;
            margin-left: -350px;
            margin-top: -145px;
            box-sizing: border-box;
            background-color: #fff;
        }
        
        .box .move {
            height: 22px;
            width: 100%;
            position: absolute;
            top: 0;
            left: 0;
            cursor: move;
        }
        
        .box h2 {
            height: 56px;
            line-height: 56px;
            text-align: center;
            font-weight: normal;
            font-size: 28px;
        }
        
        table {
            height: 88px;
            width: 480px;
            margin: 10px auto;
            border-collapse: collapse;
        }
        
        tr,
        td {
            font-size: 20px;
        }
        
        table tr td:nth-child(1) {
            text-align: right;
        }
        
        input {
            height: 32px;
            width: 290px;
            padding-left: 5px;
            border: 1px solid #ccc;
        }
        
        p {
            margin-top: 30px;
            text-align: center;
        }
        
        button {
            width: 200px;
            height: 38px;
            background-color: skyblue;
            border: none;
            cursor: pointer;
        }
        
        .close {
            height: 34px;
            width: 34px;
            line-height: 34px;
            text-align: center;
            font-size: 28px;
            border-radius: 50%;
            position: absolute;
            right: -16px;
            top: -16px;
            cursor: pointer;
            border: 1px solid #aaa;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <p class="begin">点我登陆咯!!</p>
    <div class="zz"></div>
    <div class="box">
        <div class="move"></div>
        <h2>登录会员</h2>
        <table>
            <tr>
                <td>用户名:</td>
                <td><input type="text" placeholder="请输入手机号"></td>
            </tr>
            <tr>
                <td>登录密码:</td>
                <td><input type="password" placeholder="请输入密码"></td>
            </tr>
        </table>
        <p><button>登录</button></p>
        <div class="close">×</div>
    </div>
</body>
<script>
    var zz = document.querySelector('.zz');
    var box = document.querySelector('.box');
    var begin = document.querySelector('.begin');
    var close = document.querySelector('.close');
    var move = document.querySelector('.move');
    begin.onclick = function() {
        zz.style.display = "block";
        box.style.display = "block";
    }
    close.addEventListener('click', function() {
        zz.style.display = "none";
        box.style.display = "none";
    });
    move.addEventListener('mousedown', function(e) {
        var x = e.pageX - box.offsetLeft;
        var y = e.pageY - box.offsetTop;
        document.addEventListener('mousemove', move);
        function move(e) {
            box.style.left = e.pageX - x + "px";
            box.style.top = e.pageY - y + "px";
        }
        document.addEventListener('mouseup', function() {
            document.removeEventListener('mousemove', move);
        });
    });
</script>
</html>


老师,我不知道为什么,拖动元素一直计算错误。您帮我瞅瞅。谢谢

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 587楼
WEB前端全系列/第二阶段:JavaScript编程模块/函数与对象 593楼

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .container{
            width: 850px;
            height: 200px;
            background-color: #FF8500;
            margin: 200px auto;
        }
        .top{
            width: 850px;
            height: 50px;
            background-color: #9a6e3a;
        }
        .bottom{
            width: 850px;
            height: 150px;
            background-color: #6F6D6D;
            line-height: 150px;
            text-align: center;
        }
        ul{
            list-style: none;
            width: 800px;
            height: 50px;
            float: left;
        }
        .top li{
            width: 100px;
            height: 50px;
            float: left;
            color: #FFFFFF;
            line-height: 50px;
            text-align: center;
            font-size: 14px;
            border-right: 1px solid #4182FA;
            box-sizing: border-box;
            position: relative;
        }
        p{
            width: 50px;
            height: 50px;
            background-color:#FF8500;
            float: right;
            font-size: 20px;
            text-align: center;
            line-height: 50px;
            color: #FFFFFF;
            font-weight: 700;
        }
        .context li:nth-child(2){
            display: none;
        }
        .context li:nth-child(3){
            display: none;
        }
        .top li span{
            position: absolute;
            right: 0;
            top: 0;
            background-color:black;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <div>
            <ul>
                <li>测试1<span>x</span></li>
                <li>测试2<span>x</span></li>
                <li>测试3<span>x</span></li>
            </ul>
            <p>+</p>
        </div>
        <div>
            <ul>
                <li>hello ~~测试1的内容</li>
                <li>hello ~~测试2的内容</li>
                <li>hello ~~测试3的内容</li>
            </ul>
        </div>
    </div>
    <script>
        var that;
        class Tab{
            //实现tab栏的增查删改的功能
            constructor(){
                //获取元素
                this.container = document.querySelector(".container");
                this.lisTab = this.container.querySelector(".top").querySelectorAll("li"); //tab栏里面li
                this.lisContext = this.container.querySelector(".context").querySelectorAll("li"); //内容里面的li
                this.addBtn = this.container.querySelector("p");
                this.topUl = this.container.querySelector(".top").querySelector("ul"); //获取top下的ul
                that = this;
                this.init()

            }
            //初始化方法给每个li添加绑定事件并设置自定义属性
            init(){
                   for(var i = 0; i < this.lisTab.length; i++){
                        this.lisTab[i].setAttribute("data-index",i);
                        this.lisTab[i].onclick = this.toggle;
                }
                   //给添加按钮绑定事件
                    this.addBtn.onclick = this.add;
            }
            //1.切换功能
            toggle(){
                for(var j = 0; j < that.lisTab.length;j++){
                    that.lisTab[j].style.backgroundColor = "#9a6e3a";
                    that.lisContext[j].style.display = "none"
                }
                this.style.backgroundColor = "#4182FA"; //设置当前的这个li的背景
                //这里不能使用this.lisContext因为函数里面的this指向调用者这里的this指向被点击li
                that.lisContext[this.getAttribute("data-index")].style.display = "block";
            }
            //2.添加tab栏
            add(){
                var li = document.createElement("li");
                that.topUl.appendChild(li);
                li.innerHTML = "测试" + that.lisTab.length
                //appendChild(li)添加元素后元素的长度不会发生改变
            }
            //3.删除
            remove(){}
            //4.修改
            modify(){}
        }
        new Tab(); //实例化一个tab对象
    </script>
</body>
</html>


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

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>Title</title>

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        .container{

            width: 850px;

            height: 200px;

            background-color: #FF8500;

            margin: 200px auto;

        }

        .top{

            width: 850px;

            height: 50px;

            background-color: #9a6e3a;

        }

        .bottom{

            width: 850px;

            height: 150px;

            background-color: #6F6D6D;

            line-height: 150px;

            text-align: center;

        }

        ul{

            list-style: none;

            width: 800px;

            height: 50px;

            float: left;

        }

        .top li{

            width: 100px;

            height: 50px;

            float: left;

            color: #FFFFFF;

            line-height: 50px;

            text-align: center;

            font-size: 14px;

            border-right: 1px solid #4182FA;

            box-sizing: border-box;

            position: relative;

        }

        p{

            width: 50px;

            height: 50px;

            background-color:#FF8500;

            float: right;

            font-size: 20px;

            text-align: center;

            line-height: 50px;

            color: #FFFFFF;

            font-weight: 700;

        }

        .context li:nth-child(2){

            display: none;

        }

        .context li:nth-child(3){

            display: none;

        }

        .top li span{

            position: absolute;

            right: 0;

            top: 0;

            background-color:black;

            width: 20px;

            height: 20px;

            line-height: 20px;

            text-align: center;

        }

    </style>

</head>

<body>

    <div>

        <div>

            <ul>

                <li>测试1<span>x</span></li>

                <li>测试2<span>x</span></li>

                <li>测试3<span>x</span></li>

            </ul>

            <p>+</p>

        </div>

        <div>

            <ul>

                <li>hello ~~测试1的内容</li>

                <li>hello ~~测试2的内容</li>

                <li>hello ~~测试3的内容</li>

            </ul>

        </div>

    </div>

    <script>

        var that;

        class Tab{

            //实现tab栏的增查删改的功能

            constructor(){

                //获取元素

                this.container = document.querySelector(".container");

                this.lisTab = this.container.querySelector(".top").querySelectorAll("li"); //tab栏里面li

                this.lisContext = this.container.querySelector(".context").querySelectorAll("li"); //内容里面的li

                this.addBtn = this.container.querySelector("p");

                this.topUl = this.container.querySelector(".top").querySelector("ul"); //获取top下的ul

                that = this;

                this.init()


            }

            //初始化方法给每个li添加绑定事件并设置自定义属性

            init(){

                   for(var i = 0; i < this.lisTab.length; i++){

                        this.lisTab[i].setAttribute("data-index",i);

                        this.lisTab[i].onclick = this.toggle;

                }

                   //给添加按钮绑定事件

                    this.addBtn.onclick = this.add;

            }

            //1.切换功能

            toggle(){

                for(var j = 0; j < that.lisTab.length;j++){

                    that.lisTab[j].style.backgroundColor = "#9a6e3a";

                    that.lisContext[j].style.display = "none"

                }

                this.style.backgroundColor = "#4182FA"; //设置当前的这个li的背景

                //这里不能使用this.lisContext因为函数里面的this指向调用者这里的this指向被点击li

                that.lisContext[this.getAttribute("data-index")].style.display = "block";

            }

            //2.添加tab栏

            add(){

                var li = document.createElement("li");

                that.topUl.appendChild(li);

                li.innerHTML = "测试" + that.lisTab.length

            }

            //3.删除

            remove(){}

            //4.修改

            modify(){}

        }

        new Tab(); //实例化一个tab对象

    </script>

</body>

</html>


WEB前端全系列/第二阶段:JavaScript编程模块/正则对象 595楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 596楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 600楼

百战程序员微信公众号

百战程序员微信小程序

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