标签:cti checked 下拉框 phone regexp select 手机 its radio
//回显select下拉选的值(很实用)
<select name="sex" id="select">
<option value="0">男</option>
<option value="1">女</option>
</select>
<script type="text/javascript">
var sex = ${show.sex};
alert(sex)
//获取id是select的select属性
var s = document.getElementById("select");
//获得该sex下的所有option元素,返回的是一个数组
var user_sex = s.getElementsByTagName("option");
for(var i=0;i<user_sex.length;i++){
if(user_sex[i].value==sex){
user_sex[i].selected = true;
}
}
//使用jq-validate插件校验
$("#form1").validate({
rules:{
uname:{
required:true,
minlength:2,
},
upwd:{
required:true,
minlength:5
},
upwd1:{
required:true,
equalTo:"#upwd"
},
phone:{
digits:true,
rangelength:[11,11]
}
},
messages:{
uname:{
required:‘用户名不能为空‘,
minlength:"长度至少为2",
},
upwd:{
required:‘用户密码不能为空‘,
minlength:"长度至少为5"
},
upwd1:{
required:‘请再次输入密码‘,
equalTo:"两次输入的密码不一样"
},
phone:{
digits:"请输入正确的号码",
rangelength:"请输入正确的长度"
}
}
})
</script>
//回显单选按钮的值(很实用)
<input type="radio" name="quanxian" id="auth" value="1" ${show.quanxian==1? "checked=‘checked‘":"" } />经理
//保证输入的格式是2012-2-12
<script type="text/javascript">
$("#form1").validate({
rules:{
time:{
required:true,
checkTimeExist:true
}
},
messages:{
time:{
required:‘这是必填字段‘,
checkTimeExist:‘请输入正确的格式‘
}
}
})
jQuery.validator.addMethod("checkTimeExist", function(value, element){
var ereg = /^(\d{1,4})(-)(\d{1,2})(-)(\d{1,2})$/;
var r = value.match(ereg);
if (r == null) {
return false;
}
var d = new Date(r[1], r[3] - 1, r[5]);
var result = (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[5]);
return this.optional(element) || (result);
}, "请输入正确的日期");
</script>
标签:cti checked 下拉框 phone regexp select 手机 its radio
原文地址:https://www.cnblogs.com/guagua-join-1/p/9004556.html