Uncaught TypeError:无法调用未定义的jQuery方法validate的调用 [英] Uncaught TypeError: Cannot call method 'call' of undefined jquery validate
问题描述
我的表格如下
<div id="new_image" title="Add Image">
<form id="new_image_form" action="/reg_new_img" method="POST" enctype="multipart/form-data">
<table width="0" border="0" cellspacing="0" cellpadding="6" class="table100">
<span class="astrix"></span>
<tr>
<td class="td30">Description of the Image:</td>
<td>
<input name="desc" type="text" value="" />
</td>
</tr>
<tr>
<td></td>
<td>
<input id="atag" type="hidden" name="atag" value="">
</textarea>
</td>
</tr>
<tr>
<tr>
<td>Files / Image:
<p class="text5">X-ray / Site / Document / Agreement etc.</p>
</td>
<td>
<input name="image" type="file">
</td>
</tr>
</table>
</form>
</div>
脚本如下.
$(document).ready(function () {
$("#new_image").dialog({
height: $("#new_image").height() + 150,
width: $("#new_image").width() - 450,
modal: true,
autoOpen: false,
show: {
effect: "fade",
duration: 200
},
hide: {
effect: "fade",
duration: 200
},
buttons: {
"Submit": function () {
$("#new_image_form").submit();
},
"Close": function () {
$('#new_image').dialog("close");
}
}
});
$('#new_image_form').validate({
rules: {
desc: {
required: true,
minlength: 10
},
image: {
required: true,
accept: "image/*"
}
},
messages: {
image: {
required: "only Image files accepted",
accept: "Please upload only image",
},
},
submitHandler: function (form) {
$('#new_image_form').ajaxSubmit({
success: function (data) {
console.log(data);
$('#new_image').dialog("close");
$(':input', '#new_image_form')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
}
});
parse_patients();
}
});
$('#new_image').dialog("open");
});
我在js小提琴上有这段代码
I have this code on js fiddle
http://jsfiddle.net/rakeshpatil1983/ctL7q/
当我将图像文件实际放在chrome浏览器控制台上时,单击提交"时出现错误
I'm getting an error when i click submit when I actually put image file on the chrome browser console
未捕获的TypeError:无法调用未定义的方法调用"
Uncaught TypeError: Cannot call method 'call' of undefined
我无法解决此问题.这段代码似乎可以在其他页面上使用.
I'm not able to fix this. This code seems to work in some other page.
推荐答案
在您的#new_image_form规则中,"accept"不是默认的jQuery Validator默认规则.您必须使用以下默认规则之一: Jquery Validate-类列表或定义您自己的自定义规则,例如: jQuery Validate Plugin-How创建一个简单的自定义规则?
In your rules for #new_image_form, "accept" is not a default jQuery Validator default rule. You must either use one of these default rules: Jquery Validate - List of Classes or define your own custom rule like such: jQuery Validate Plugin - How to create a simple custom rule?
来自以下注释:有一个名为accept的规则,它是jQuery Validate插件包的一部分.您只需添加其他方法文件即可使用它.
from comments below: there is a rule called accept that is part of the jQuery Validate plugin package. You simply have to include the additional-methods file in order to use it.
这篇关于Uncaught TypeError:无法调用未定义的jQuery方法validate的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!