jquery validate异步验证时多参数传递
程序员文章站
2022-07-06 07:59:43
...
JSP代码:
<form role="form" class="add_form"> <input type="hidden" name="adminUserCategory.id" value="${adminUserCategory.id}" class="categoryId"> <div class="form-group input-name"> <label for="firstname" class="col-sm-2 control-label">名称</label> <div class="col-sm-10"> <input type="text" class="form-control" id="firstname" placeholder="请输入名称" name="adminUserCategory.name" value="${adminUserCategory.name}" style="width: 50%;float: left;"> <span class="err-class"></span> </div> </div> <div class="form-group input-description"> <label>描述</label> <textarea class="form-control" rows="5" name="adminUserCategory.Description">${adminUserCategory.description}</textarea> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">保存</button> </div> </div> </form>
js中validate的rules的代码:
rules:{ "adminUserCategory.name":{ required:true, remote:{ type:"post",//数据请求方式 url: $('.domain_name').val()+"/Stat/checkUserCategoryNameExist.action",//异步验证路径 data:{ "adminUserCategory.name":function(){ return $("#firstname").val(); }, "adminUserCategory.id":function(){ return $(".categoryId").val();//没有这一行,获取不到数据 } }, dataType:"html", dataFilter:function(data,type){//AJAX异步返回数据 var flag = eval("("+data+")"); if(flag){ return true; }else{ return false; } } } } }
这样,adminUserCategory.name与adminUserCategory.id都能获取到界面的参数了
上一篇: idea 内存溢出配置
下一篇: jquery常用案例