前端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. 屏蔽F12审查元素,禁止使用右键菜单

    一.屏蔽F12审查元素 <script type="text/javascript"> document.onkeydown = function() { ) { al ...

  2. python request Payload 数据处理

    普通的http的post请求的请求content-type类型是:Content-Type:text/html; charset=UTF-8, 而另外一种形式request payload,其Cont ...

  3. [UE4]线性插值Lerp

  4. 人只能靠自己 编写ETL框架使用工具

    今天开始接触到大数据模块,etl 框架工具目的是对医院中的PACS 和RIS 系统进行数据提取: 目前只查到需要用etl工具,大数据板块 ,具体实现仍是大问题 有缘人看到可以留言提示啊:

  5. DevExpress 折线图和柱状图的绘制与数据绑定

    DevExpress 组件是一个非常丰富和强大的组件,适合各种可视化图形的绘制与展示,在数据分析展示中是个很有帮助的,网上也有很多关于这方面的文章,关于折线图或柱状图的画法,以下是自己在工作中接触到的 ...

  6. 如何解决vux不兼容安卓低版本问题

    最近做移动端H5页面用VUX来写UI组件这块.ios测试的时候没啥大问题,不过在4.4版本的华为手机上测试就崩了.接下来详细记述下崩的几个点. 第一:vux自带的提示框,在低版本安卓系统上全不是居中显 ...

  7. react基础学习 一

    1. 搭建环境 安装react脚手架  >npm install create-react-app -g 创建文件            >create-react-app 项目名称 启动 ...

  8. zabbix3.x添加华为(93069306)网络设备详解

    转载自:https://www.cnblogs.com/yinzhengjie/p/6768006.html 前言: 欢迎加入:高级运维工程师之路 598432640 相信大家在看我的文章之前,也看过 ...

  9. 聊一聊Java泛型的擦除

    最近看了<thinking in java>的第十五章泛型,感觉有些东西需要记录下来. 泛型是Java SE5才被引入的概念,现在我的工作中泛型主要使用在集合,这样可以知道set()和ge ...

  10. 将eclipse dynamic web project部署到指定的tomcat软件下的webapps文件夹中