jQuery 插件 validate() :将插件应用于 ajax 注入表单

发布于 2024-08-26 06:31:21 字数 295 浏览 6 评论 0原文

我的问题非常简单:我尝试使用 jQuery 验证插件来创建在某些用户操作后注入的表单。

我的问题主要是:

  • 我可以使用实时支持来绑定输入上的更改事件,如下所示

     $("#adresseLivraisonPro").live('change',function(e){
        $("#adresseLivraisonPro").validate({
    

    但这使得我的表单验证当且仅当用户更改输入...

您将如何解决这个问题?

My issue here is quite simple : i'm trying to use the jQuery validate plugin to a form that gets injected after certain user actions.

My problem mostly is that :

  • I could use live support to bind the change event over inputs, like this

        $("#adresseLivraisonPro").live('change',function(e){
        $("#adresseLivraisonPro").validate({
    

    But this makes my form validated if and only if user changes inputs...

How would you surround that problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

女皇必胜 2024-09-02 06:31:21

您可以使用 AJAX 调用的回调函数将验证应用于表单。

    $("myformarea").load("urlof form.php", function(){
            $("The Form").validate();
    });

因此,验证是在加载表单后应用的。

You can use the callback function of the AJAX call to apply the validation to the form.

    $("myformarea").load("urlof form.php", function(){
            $("The Form").validate();
    });

So the validation is applied after the form is loaded.

書生途 2024-09-02 06:31:21

注入表单时应用验证

apply the validation when you inject the form

帅气称霸 2024-09-02 06:31:21

假设你做了类似的事情

... user action ...
... retrieve formhtml somehow ajax/stringconcat ...
$("#formcontainer").html(formhtml); //inject form
$("#formcontainer form").validate(); //wire validation to form

Assuming you do something like

... user action ...
... retrieve formhtml somehow ajax/stringconcat ...
$("#formcontainer").html(formhtml); //inject form
$("#formcontainer form").validate(); //wire validation to form
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文