前端form表单提交时遇到个问题,一直报错如下

首先说结论:form是个js对象,不是jQuery对象,不能用jquery对象的方法。

代码是:

$(document).ready(function() {
//$("#name").focus();
$("#inputForm").validate({
onfocusout: function(element){
$(element).valid();
},
submitHandler: function(form){
loading('正在提交,请稍等...');
$.ajax({
url:form.attr("action"),
type:form.attr("method"),
data:form.serialize(),
success:function(res){
if(res.type=='success'){
showTip(res.content);
var d = parent.dialog.get('distributeFund');
setTimeout(function(){
d.close(res.type);
}
,2000);//单位毫秒 }
},
error:function(e){
alert(e.type);
}
})
},
errorContainer: "#messageBox",
errorPlacement: function(error, element) {
$("#messageBox").text("输入有误,请先更正。");
if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
error.appendTo(element.parent().parent());
} else {
// error.insertAfter(element);
error.appendTo(element.next());
}
}
});
}); 一开始以为是form没定义,找了半天也解决不了。最后看chrome的sources栏,form不是undefind的样子。
主要是因为,这里传入的form是js对象,而form.attr()的用法是jquery的方法。报错日志路径中也是提示了是jQuery的错误。所以把ajax里的form改为$(form),由js对象改为jQuery对象,方法就能正常使用了。

最新文章

  1. 通过nginx代理之后,获取客户端ip
  2. SQL排序
  3. Hibernate一对一关系映射
  4. 深入浅出设计模式——建造者模式(Builder Pattern)
  5. 【SQL查询】集合查询之INTERSECT
  6. uva 839 Not so Mobile-S.B.S.
  7. Class文件结构
  8. while,do while和for循环语句的用法
  9. 2016年10月24日 星期一 --出埃及记 Exodus 19:8
  10. spring WebServiceTemplate 调用 axis1.4 发布的webservice
  11. 【POJ2094】【差分序列】Angry Teacher
  12. 21、javascript 基础
  13. Unity 异步加载场景
  14. Swift语言中与C/C++和Java不同的语法(五)
  15. 视图和URL配置
  16. Go语言基础(二)
  17. 【HDU - 1429】胜利大逃亡(续) (高级搜索)【状态压缩+BFS】
  18. 朱晔和你聊Spring系列S1E6:容易犯错的Spring AOP
  19. Visual Studio 2017 IDE之xml过大报错
  20. Codeforces Round #486 (Div. 3) D. Points and Powers of Two

热门文章

  1. node vue
  2. [UE4]让箭头保持水平的第二种方法:Combinrotators、Delta(Rotator)
  3. 微信小程序企业给零钱打款 提示未配置api发起,请查看产品中心企业付款配置
  4. DB2调优摘要
  5. PhysicalBasedRendering(一)物理篇
  6. C语言博客作业5--指针
  7. oracle入坑日记<六>自增列创建和清除(含序列和触发器的基础用法)
  8. 简单的PHP上传图片和删除图片示例代码
  9. HU-1043
  10. asp.net 微信开发(一)