前端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. C# 6.0:新的Dictionary Initializer

    初始化Dictionary不是什么新东西,你可以简单的通过Collection Initializer来初始化一个Dictionary,这是从C#3.0就有的特性.Collection Initial ...

  2. 删除DataTable的指定行(Lambda)

    DataTable dtTcu = GetAllTcuInfoBySdId(sdId); DataTable dtToesm = GetAllToesmBySdId(sdId); foreach (D ...

  3. C++类的组合例子

    Line类调用Point类的两个对象p1,p2作为其数据成员,计算线段长度 组合类构造函数定义的一般形式为: 类名::类名(形参表):内嵌对象1(形参表),内嵌对象2(形参表)... {类的初始化} ...

  4. Python基础之变量

    变量的作用 用来记录状态的变化 全局变量 全局变量一般使用大写字母来进行区分 顶头写 定义过之后在整个程序中都能使用, 如果需要在函数中使用并修改全局变量的值需要加上global关键字: 如果函数内部 ...

  5. centos 下安装mulval工具

    我这里采用的是centos 6.5版本系统 MulVAL是企业网络安全分析的工具.它使用漏洞扫描程序(OVAL / Nessus)作为攻击路径生成的数源,其中包括扫描结果和网络可访问性信息. 在这之前 ...

  6. scrapy使用指南

    创建scrapy项目: scrapy startproject 项目名 cd到项目名下 scrapy genspider 爬虫名 www.baidu.com(网站网址) 之后按照提示创建爬虫文件(官方 ...

  7. git 推送远程仓库和删除远程仓库文件

    提交到远程仓库需要现在GitHub或gitlab上创建项目,然后才能连接到远程仓库 1.连接远程仓库 # git remote add origin https://github.com/xxxxx ...

  8. Spring 回滚事务@Transactional

    @Transactional   spring 事务注解 默认遇到throw new RuntimeException("...");会回滚 需要捕获的throw new Exce ...

  9. Jmeter使用插件监控服务器资源的使用情况

    环境准备 客户端: 1)安装最新版的Jmeter,目前为 Jmeter5.0 2)安装插件管理器:JMeterPlugin jmeter-plugins-manager.jar下载完成之后,将下载的j ...

  10. RF:win10跑用例过程中有中文日志会显示非中文

    问题:RobotFramework在win10跑用例过程中有中文日志会显示非中文,如截图: 解决:  C:\Python27\Lib\site-packages\robot\utils\unic.py ...