[英]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.