我正在尝试验证包含CKEditor支持的textarea的表单。但是现在,它根本不显示任何错误,也没有提交代码。
我已经阅读了与该主题相关的所有答案,但我的代码无法正常工作。
到目前为止,这是我得到的:
if(jQuery().validate) {
$("#submit_button").click(function(e){
e.preventDefault();
CKEDITOR.instances.editor1.updateElement();
$(" #content_form ").validate({
ignore: "input:hidden:not(input:hidden.required),input:hidden:not(input:hidden.editor1)",
errorPlacement: function(error, element) {
if (element.attr("name") == "editor1")
{
error.insertBefore("#editor1");
}
else
{
error.insertAfter(element);
}
},
rules: {
title: {
required: true,
minlength: 5
},
editor1: {
required: true,
minlength: 10
},
imglink: {
url:true
},
},
messages: {
title: "The title field is required.",
editor1: "The content field is required.",
imglink: "You must provide a valid URL."
}
});
});
}
如果您能帮助解决这个问题,我将不胜感激。
提前致谢。
您的问题之一是对该.validate()
方法的根本误解。
您的代码...
$("#submit_button").click(function(e){
....
$(" #content_form ").validate({
....
由于.validate()
是插件的初始化方法,因此通常在DOM ready事件中调用一次。它不属于提交按钮的click
处理程序事件之内,因为插件需要在单击事件之前进行初始化。(它不会被多次调用,因为所有后续调用都会被忽略。)此外,该插件捕获各种click事件并根据需要自动执行任何已定义的验证。
$(document).ready(function() { // <-- DOM Ready event
....
$("#content_form").validate({ // <-- Initialize the plugin on this form
....
插件的基本演示:http : //jsfiddle.net/EN3Yb/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句