前端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对象,方法就能正常使用了。

Uncaught TypeError: form.attr is not a function 解决办法的更多相关文章

  1. jQuery报错:Uncaught TypeError: _this.attr is not a function

    问题:想通过延时把置灰的按钮再次复原,代码如下: $("#sendEmailCode").on("click", function() { var _this ...

  2. Uncaught TypeError: Cannot set property 'onclick' of null解决办法

    如果把js内容直接放在这个head标签以内,button按钮不能正常点击更换body的背景颜色,报错提示:demo6.html:16 Uncaught TypeError: Cannot set pr ...

  3. 使用zepto中animate报错“Uncaught TypeError: this.bind is not a function”的解决办法

    在使用zepto时,我先引入zepto.min.js,然后引入fx.js,但是在使用animate函数时,控制台却报如下错误: Uncaught TypeError: this.bind is not ...

  4. jquery.js 3.0报错, Uncaught TypeError: url.indexOf is not a function

    转载自:http://majing.io/questions/432   问题描述 jQuery升级到3.0.0后类型错误 jquery.js:9612 Uncaught TypeError: url ...

  5. Uncaught TypeError: (intermediate value)(...) is not a function 上一个方法结束没有加分号; 代码解析报错

    Uncaught TypeError: (intermediate value)(...) is not a function 别忽略了,  第一个方法后面的结束 分号; 不起眼的,引来麻烦, 哎,规 ...

  6. jquery3.1.1报错Uncaught TypeError: a.indexOf is not a function

    jquery3.1.1报错Uncaught TypeError: a.indexOf is not a function 使用1.9就没有问题,解决办法: 就是把写的代码中: $(window).lo ...

  7. jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function

    jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function 使用.load()绑定事件时报错,Uncaught TypeError: e.i ...

  8. 简记webpack运行报错 Uncaught TypeError: self.postMessage is not a function

    说好2017Fix的还是能重现,可能项目的版本比较旧了,简要记录解决办法 1.错误: index.js?bed3:67 Uncaught TypeError: self.postMessage is ...

  9. vue项目报错1 Vue is a constructor and should be called with the `new` keyword && jquery.js?eedf:3850 Uncaught TypeError: this._init is not a function...

    Vue is a constructor and should be called with the `new` keyword Uncaught TypeError: this._init is n ...

随机推荐

  1. Solr4.7.0连接MySQL

    1.把Mysql的Jar包  例如:mysql-connector-java-5.1.8-bin.jar  或其他版本 放到D:\apache-tomcat-7.0.57\webapps\solr\W ...

  2. Dell Inspiron 620 / Vostro 260 BIOS 开启 AHCI 模式

    1.Dell Vostro 260 台式机,WIN7 旗舰版   2.登陆 DELL 官方支持站点,获取 MS-A10.exe 安装文件   3.从网络中获取 AMIBCP.exe 工具,双击打开此程 ...

  3. 7.2 if else 语句

    7.2 if else 语句 if else语句的通用形式是: if ( expression ) statement1 else statement2 如果expression为真(非0),则执行s ...

  4. Linux安装/升级pip

    Linux安装/升级pip 1.执行脚本 # wget https://bootstrap.pypa.io/get-pip.py # 如果没有 wget,先安装 wget # yum -y insta ...

  5. [Notepad++]Notepad++怎么实现双视图/双窗口?

    作为windows下非常优秀的开源代码编辑器,Notepad++是工程师必备代码编辑器.相比较之下,老一辈文本编辑器如ultraedit,editplus,就显得繁琐.冗余.疲惫.我使用过Notepa ...

  6. RAS算法简单示例(Java版)

    RSA算法——由三位发明者Ronald Rivest.Adi Shamir 和 Leonard Adleman 姓氏的首字母拼在一起组成. RSA算法属于“公开密钥加密技术”,其加密和解密的秘钥不同. ...

  7. 思维导图工具XMind下载

    XMind 是一款非常实用的商业思维导图软件,全力打造易用.高效的可视化思维软件,强调软件的可扩展.跨平台.稳定性和性能,致力于使用先进的软件技术帮助用户真正意义上提高生产率.XMind 支持 在Wi ...

  8. 一个WPF只能输入数字的行为。

    没啥好说的,直接上代码: public class NumberInputBehaviour : Behavior<TextBox> { protected override void O ...

  9. 我的第一个flutter程序

    环境搭建好了之后,终于可以开始flutter的学习,废话少说先开始‘Hello World’. 创建好flutter项目之后,打开设备模拟器 打开之后 准备ok,开始编码 -------------- ...

  10. Window中的Docker 拉取Mysql镜像 并在本地Navicate链接

    首先本地   拉取mysql镜像 以下是所有mysql镜像 我自己下载的为5.6   下面 以5.6为例:(拉取mysql5.6镜像) docker pull mysql:5.6 创建一个容器 doc ...