简体   繁体   English

我想要一个按钮,单击它时首先要检查密码(如果密码是abcd),而不是显示另一个提交按钮,否则显示警报

[英]i want button on which when click it first check the password if the password is abcd than shows the another submit button else show an alert

 <form action="#" method="post" target="_blank">
        <div id = "another sub">
        </br>
        <input type = "password" size = "25px" id="pswd">
        </br>
        </div>
        <button><a href="table.html" target="_blank" onclick="checkAddress('password');" >Submit</a></button>
<script>
        function checkAddress(field){
            var val = document.getElementById("pswd").value;
            if  (val === "abcd"){
                alert ("Matched");
            }
            else {
                alert("Try for Next Time");
            }
        }
        </script>
    </form>

i have a form here in which it first check password than takes to the another page 我在这里有一个表单,在该表单中,它首先检查密码,而不是转到另一页

You have to Add your Script Tag below the form tag or you can add it at the end of the page before the body closing tag, make sure to include the js in the page 您必须将脚本标签添加到form标签下,或者可以将其添加到页面末尾的body结束标签之前,请确保将js包含在页面中

<form action="#" method="post" target="_blank">
    <div id = "another sub">
    </br>
    <input type = "password" size = "25px" id="pswd">
    </br>
    </div>
    <button onclick="checkAddress('password');">Submit</button>
</form>
 <script>
    function checkAddress(field){
        var val = document.getElementById("pswd").value;
        if  (val === "abcd"){
            alert ("Redirect To page if Matched Found");
            window.location = "http://www.redirecturlhere.com/"
        }
        else {
            alert("Try for Next Time");
        }
    }
    </script>

In your case, you don't need <form> and <a> tags. 就您而言,您不需要<form><a>标记。 Just redirect when password is input correct. 只要输入正确的密码即可重定向。

 function checkAddress(field) { var val = document.getElementById("pswd").value; if (val === "abcd") { alert("Matched"); document.location.href = 'table.html'; } else { alert("Try for Next Time"); } } 
 <div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress();">Submit</button> 

Don't use a form to avoid the reload: 不要使用表格来避免重新加载:

 function checkAddress(field) { var val = document.getElementById("pswd").value; if (val == "abcd") { alert("Matched"); location.href = "table.html"; } else { alert("Try for Next Time"); } } 
 <div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress()">Submit</button> 

It would be wise to not use inline js, using a examplename.js file that is loaded would be better solution. 不使用内联js是明智的,使用已加载的examplename.js文件将是更好的解决方案。

 function checkAddress(field) { var val = document.getElementById("pswd").value; if (val === "abcd") { alert("Matched"); document.location.href = 'table.html'; } else { alert("Try for Next Time"); } } 
 <div id="another sub"> <input type="password" size="25px" id="pswd"> </div> <button onclick="checkAddress();">Submit</button> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我点击提交按钮我的javascript第一个警报框显示在移动设备但在桌面上工作正常 - when I click on submit button my javascript first alert box show in mobile device but works fine in desktop Vue 当我点击显示密码时,提交按钮有效 - Vue When I click for showing password, submit button works 单击“提交”按钮时如何在JavaScript警报中回显复选框 - How to echo Check Box in JavaScript Alert When Click on Submit Button 单击提交按钮后,jQuery 显示警报 - Jquery show alert after click submit button 单击提交按钮时仅显示第一个输入错误 - Show only first input error when click on submit button 我要始终在单击“提交”按钮时删除div容器吗? - I want to remove the div container always when click submit button? 我有两个复选框“接受”和“拒绝”并提交按钮。 当我单击提交按钮时,它应该检查勾选了哪个复选框 - I have two check boxes “Accept” and “Decline” and submit button. When i click on submit button it should check the which check box is ticked 单击按钮显示警报 - Show alert on a button click 当我单击一个按钮时,我只想在另一个元素包含特定文本时才显示一个元素 - When I click on a button, I want to show an element only if another element contains a specific text 为什么我的密码生成器在我单击按钮之前显示密码? - Why is my password generator showing the password before I click the button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM