老师没有实现出来,问题出在哪里

来源:2-13 编程练习

siegelions

2021-01-14 13:39:16

<!DOCTYPE html>

<html>


<head>

    <meta charset="UTF-8">

    <title>Location 对象</title>

</head>

<style>

    *{

    padding:0;

    margin:0;

    }

    div{

        margin:30px ;

        width: 400px;

        height: 100px;

        position: absolute;

        top: 50%;

        left: 50%;

        margin-top: -50px;

        margin-left: -200px;

        text-align: center;

    }

</style>

<body>

   <!-- 补充代码 -->

   <div>

      用户名:<input style="text" id="username"></br></br>

      密码: &nbsp&nbsp<input style="password" id="pwd"></br></br>

      <button id="submit">提交</button>

   </div>

  <script>

       var username=document.getElementById("username");

       var pwd=document.getElementById("pwd");

       var submit=document.getElementById("submit");

       submit.onclick=function(){

           if (username.value == "张三" && pwd.value == "123456") {

                window.location = "http://www.imooc.com";

            } else {

                alert('信息错误');

            }

       }

   

  </script>

   

</body>


</html>


写回答

1回答

好帮手慕星星

2021-01-14

同学你好,测试代码效果没有问题。老师加了一行弹出‘正确’的代码,方便看效果

http://img.mukewang.com/climg/5fffe14f0971dc7707350257.jpg

错误以及正确都可以提示

http://img.mukewang.com/climg/5fffe0e909280e2c06910624.jpg

http://img.mukewang.com/climg/5fffe10809d7579206610602.jpg

另外,代码还需要优化:

1、虽然效果没问题,但是input框type属性值写错了,写为了style,需要修改,否则密码处不会变为小圆点

http://img.mukewang.com/climg/5fffe19009236ac208110291.jpg

2、&nbsp;间隔别忘记加分号结尾

http://img.mukewang.com/climg/5fffe21909cbe10906770176.jpg

自己再修改测试下,祝学习愉快!

0

0 学习 · 15276 问题

查看课程