简体   繁体   English

如何编写一个程序,以确保在两个字段中输入的密码都匹配?

[英]How to write a program that will make sure that the passwords entered in both fields match?

I want the text "password set" to display if passwords in both fields match? 如果两个字段中的密码都匹配,我希望显示文本“密码集”吗? What am i doing wrong? 我究竟做错了什么? also what are the rules regarding having brackets within script? 还有在脚本中使用方括号的规则是什么? can i have two functions within the same script tag? 同一脚本标签中可以有两个功能吗?

<p>First name:  <input type="text" id="fname" /></p>
<p>Surname: <input type="text" id="sname" /></p>
<p>Date of birth:   <input type="text" id="dob" /> (Please enter as dd/mm/yyyy)</p>
<button onclick="user()">Generate Username</button>
<p id="username"></p>
    <p id="match"></p>

<p>Please enter a password for your account.</p>
<p>Enter password:  <input type="text" id="password1" /></p>
<p>Re-enter password:   <input type="text" id="password2"/></p>
<button onclick="password()">Submit Password</button>

<script>
    function user() {
        document.getElementById("username").innerHTML = document.getElementById("fname").value+document.getElementById("sname").value+document.getElementById("dob").value.slice(-4)
    }

    function password() {
        if document.getElementById("password1").value = document.getElementById("password2").value
            document.getElementById("match").innerHTML = " Your password has been set "
    }
</script>

I hope this helps :) 我希望这有帮助 :)

 function password(){ var pass1 = document.getElementById("password1").value; var pass2 = document.getElementById("password2").value; if(pass1 == pass2){ alert("password match"); }else{ alert("password do not match"); } } 
 <p>Enter password: <input type="password" id="password1" /></p> <p>Re-enter password: <input type="password" id="password2"/></p> <button onclick="password()">Submit Password</button> 

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

相关问题 如果两个字段均为空,则检查密码匹配将返回“密码匹配” - Checking password match returns “Passwords match” when both fields are empty JavaScript —如何制定规则以确保用户输入的值介于两个特定数字之间 - JavaScript — How can I make a rule to make sure a user entered a value between two specific numbers 如何检查以确保表单字段不是空字符串? - How do I check to make sure form fields are not empty strings? 使用是的,我如何确保 2 个字段需要不同 - Using Yup how do i make sure that 2 fields need to be different 如何确保如果在一个字段(其他)字段/下拉列表中输入了值,则必须填写/选择 - How to make sure that if value is entered in one field other (accompanying) field/dropdown list must be filled/selected CSHTML。 需要确保输入字段 - CSHTML. Need to make sure field(s) are entered 如果输入了两个必填字段,则 XMLHttpRequest 不会触发 POST - XMLHttpRequest does not fire for POST if both required fields are entered jQuery确保填写所有表单字段 - jQuery make sure all form fields are filled 检查以确保所有字段都已填写 - Check to make sure all fields are filled Jquery 如果资金不足2900,您如何确保不能再次按下两个按钮? - How would you make sure that you can't press both the buttons again if the money is under 2900?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM