form action="success.html" id="form">
<p>
姓名:<input type="text" name="text" id="xm">
</p>
<p>
密码:<input type="password" name="pwd" id="pwd">
</p>
<p>
再次输入密码:<input type="password" name="repwd" id="repwd">
</p>
<input type="submit" value="submit">
<input type="button" name="" id="btn">
</form>
<script>
let form = document.getElementById('form');
let xm = document.getElementById('xm');
let pwd = document.getElementById('pwd');
let repwd = document.getElementById('repwd');
let btn = document.getElementById('btn');
btn.onclick = function(){
console.log(xm.value)
}
form.onsubmit = function () {
if(xm.value==''){
alert('姓名不能为空');
return false;
}
for(let i=0;i<xm.value.length;i++){
let s = xm.value.substring(i,i+1);
if(isNaN(s)==false){
alert('姓名不能包含数字')
return false;
}
}
if(pwd.value==''){
alert('密码不能为空');
return false;
}
if(pwd.value.length<6){
alert('密码不能小于6位');
return false;
}
if(pwd.value.trim()!=repwd.value.trim()){
alert('两次输入的密码要一致');
return false;
}
return true;
}
</script>