输入式密码不可移动

我有这个代码,无论我做什么,第一个输入都不会移动,唯一让它移动的是 float:right; 但我不希望它像这样我什至创建了这个 div->P 所以它可能会移动。有没有人遇到过这个问题?


它可能会干扰我的js吗?这是我唯一能想到的 rn


                .inner {

                    display:inline-block;

                    margin-right:500px;

                }


                .pswd {

                    display:inline-block;

                    margin-right:500px;           

                }


          </style>

        </head>

        <body>

            <div class="P">

                <input class="inner" type="password" id="pswd">

                <input class="inner" type="button" value="Submit" onclick="checkPswd();"/>

            </div>


        <script type="text/javascript">

            function checkPswd() {

                var confirmPassword = "admin";

                var password = document.getElementById("pswd").value;

                if (password == confirmPassword) {

                     window.location="A.html";

                }

                else{

                    alert("Password incorrect.");

                }

            }

        </script>


海绵宝宝撒
浏览 137回答 2
2回答

守候你守候我

如果您使用 ID 选择器而不是类选择器(即使用#而不是.),这应该可以工作:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #pswd {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display:inline-block;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-right:500px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

隔江千里

有多种方法可以在屏幕上垂直和水平居中对齐 div。我也用过display:flex。&nbsp; 'use-strict'&nbsp; function checkPswd(form) {&nbsp; &nbsp; const confirmPassword = "admin";&nbsp; &nbsp; let passwordProvided = form.elements.newPassword.value;&nbsp; &nbsp; if (passwordProvided === confirmPassword) {&nbsp; &nbsp; &nbsp; // If correct&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; // If failure&nbsp; &nbsp; }&nbsp; &nbsp; // to prevent default action&nbsp; &nbsp; return false;&nbsp; }.form--wrapper {&nbsp; width: 150px;&nbsp; height: 150px;&nbsp; position: absolute;&nbsp; top: 0;&nbsp; bottom: 0;&nbsp; left: 0;&nbsp; right: 0;&nbsp; margin: auto;}form {&nbsp; display: flex;&nbsp; flex-direction: column;&nbsp; justify-content: center;&nbsp; height: 100%;&nbsp; width: 100%;&nbsp; border: 2px dashed orange}<div class="form--wrapper">&nbsp; <form name="change-password" onsubmit="return checkPswd(this)">&nbsp; &nbsp; <input class="inner" name="newPassword" type="password">&nbsp; &nbsp; <input class="inner" type="submit" value="Submit" />&nbsp; </form></div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript