1.表格
如图所示
<table border="" cellspacing="" cellpadding="">
<tr>
<td>账户:</td>
<td>
<input type="text" name="uname" id="uname" value="" οnblur="checkUname()" />
</td>
<td>
<label id="msg1"></label>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="pwd1" id="pwd1" value="" οnblur="checkPwd(1)" />
</td>
<td>
<label id="msg2"></label>
</td>
</tr>
<tr>
<td>确认密码:</td>
<td>
<input type="password" name="pwd2" id="pwd2" value="" οnblur="checkEquals()" />
</td>
<td>
<label id="msg3"></label>
</td>
</tr>
<tr>
<td>家庭住址:</td>
<td>
<select name="province" id="province" οnchange="changeOpt()">
<option value="请选择省份">--请选择省份--</option>
<option value="河南省">--河南省--</option>
<option value="四川省">--四川省--</option>
<lect>
<select name="cities" id="cities">
<option value="请选择城市">--请选择城市--</option>
<lect>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="button" id="btn" value="提交" />
</td>
</tr>
</table>
function checkPwd(){
var reg1=/^\w(6,)$/
var password=document.getElementById("pwd1").value
if(reg1.test(password)){
document.getElementById("msg2").innerHTML="密码格式不正确"
return true
}else {
document.getElementById("msg2").innerHTML = "密码格式不正确"
return false
}
}
function checkEquals(){
var reg1=/^\w(6,)$/
var password=document.getElementById("pwd2").value
if(reg1.test(password)){
document.getElementById("msg3").innerHTML="确认密码格式不正确"
return true
}else {
document.getElementById("msg3").innerHTML = "确认密码格式不正确"
return false
}
}
function checkPwd(n){
var pwd1=document.getElementById("pwd1").value
var pwd2=document.getElementById("pwd2").value
var reg=/^\w{6,}$/
if(n==1){
if(reg.test(pwd1)){
document.getElementById("msg2").innerHTML="密码格式正确"
return true
}else{
document.getElementById("msg2").innerHTML="密码格式不正确"
return false
}
}else{
if(reg.test(pwd2)){
document.getElementById("msg3").innerHTML="确认密码格式不正确"
return true
}else{
document.getElementById("msg2").innerHTML="密码格式不正确"
return false
}
}
}
function checkEquals(){
var pwd1=document.getElementById("pwd1").value
var pwd2=document.getElementById("pwd2").value
// 验证密码格式是否正确
if(checkPwd(2)){
if(pwd1==pwd2){
document.getElementById("msg3").innerHTML="密码和确认密码一致"
return true
}else{
document.getElementById("msg3").innerHTML="密码和确认密码不一致"
return false
}
}
}
function changeOpt(){
var cityList=new Array();
cityList=['请选择省份']=['请选择城市'];
cityList=['河南省']=['郑州','商丘','南阳','洛阳','三门峡','平顶山'];
cityList=['四川省']=['成都','锦阳','自贡','德阳','泸州'];
// 获取选中的下拉列表项(省份)
var province =document.getElementById("province").value
// 将下拉列表清空
document.getElementById("cities").options.length=0
for (var i=0;i<cityList[province].length;i++) {
var opt=new Option(cityList[province][i],cityList[province][i])
document.getElementById("cities").options.add(opt)
}
}
2.复选框的点击事件
如图所示