没有表单标签的jQuery验证 [英] jQuery validation without form tag

查看:82
本文介绍了没有表单标签的jQuery验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有许多输入的表单",在提交"按钮上,我调用了一个javascript函数,该函数操纵信息并通过ajax发送到php文件.

I have a "form" with many inputs and at the submit button I call a javascript function that manipulate the info and send by ajax to a php file..

我可以添加一个没有动作URL的表单标签,以使用jquery验证来验证我的表单"吗?还是我必须手动进行验证?

I can add a form tag without an action url to validate my "form" with the jquery validate? Or I have to do manually the validation?

谢谢!

推荐答案

我有一个表单",其中包含很多输入内容,在提交"按钮上,我称 处理信息并通过ajax发送到php的javascript函数 文件"

"I have a 'form' with many inputs and at the submit button I call a javascript function that manipulate the info and send by ajax to a php file"

绝对要求您具有<form></form>标签,以使jQuery Validate插件正常运行,或完全正常运行.

It is absolutely required that you have <form></form> tags for the jQuery Validate plugin to function properly, or at all.

如果使用ajax,则必须将您的ajax放入 jQuery Validate插件.参见下面的示例.

If you use ajax, you must put your ajax inside the submitHandler of the jQuery Validate plugin. See below for my example.

我可以添加没有动作URL的表单标签,以通过jquery验证来验证我的表单"吗?"

"I can add a form tag without an action url to validate my "form" with the jquery validate?"

是的,您可以删除或阻止action并仍然使用jQuery Validate.

Yes, you can remove or block the action and still use jQuery Validate.

请参阅演示: http://jsfiddle.net/NEPsc/3/

ajaxreturn false放在submitHandler中,将不会进行常规提交:

Put your ajax and a return false in the submitHandler and no regular submission will occur:

$(document).ready(function() {

    $('#myform').validate({ // initialize plugin
        // your rules & options,
        submitHandler: function(form) {
            // your ajax would go here
            return false;  // blocks regular submit since you have ajax
        }
    });

});


编辑:

根据OP的注释,要使用input type="button"而不是input type="submit",则需要使用click处理程序. 不需要任何内联JavaScript.完全删除onClick函数.

As per OP's comments, to use a input type="button" instead of a input type="submit", you'll need to use a click handler. There is no need to have any inline JavaScript. Remove the onClick function entirely.

查看更新的演示: http://jsfiddle.net/NEPsc/5/

See updated demo: http://jsfiddle.net/NEPsc/5/

这篇关于没有表单标签的jQuery验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆