EasyUI validatebox 自定义ajax验证用户名是否已存在
<td><input type="text" id="userName" name="userName" class="easyui-validatebox" validType="userName[6,30]" required="true"/></td>
JS
$.extend($.fn.validatebox.defaults.rules, {
userName: {
validator: function(value,param){
var data0 = false;
if(value.length >= param[0] && param[1] >= value.length) {
$.ajax({
type: "POST",async:false,
url:'${pageContext.request.contextPath}/user/validate.do',
dataType:"json",
data:{"userName":value},
async:false,
success: function(data){
data0=data.valid;
}
});
}else{
param[2] = "请输入"+param[0]+"-"+param[1]+"位字符.";
return false;
}
param[2] = "用户名称已存在.";
return data0;
},
message: ""
}
});