JQuery Form Validation Not working on newly created elements

前端 未结 2 1019
我在风中等你
我在风中等你 2021-01-15 01:17

Am having a few issues with the Jquery Validation plug in, and wondering if anyone can assist.

At the moment, the plug in works with any form elements currently on t

相关标签:
2条回答
  • 2021-01-15 01:30

    This is because $("#addRelease").validate adds event Handlers to your HTML Elements the time it is called. You have to call it again after inserting new elements.

    0 讨论(0)
  • 2021-01-15 01:48

    Hard to tell without seeing your code, but you might need to bind the "validate()" method after you have inserted the html into your page because the #addRelease element can't be found by jQuery until the user initiates the ajax call (by clicking) which then adds that element to the page.

    // Add release form
    $(function(){
        $('body#true #releases p a').click(function(){
            // Grab form using Jquery
            $.get('http://localhost:8500/mxRestore/views/viewlets/forms/ajax/a_addRelease.cfm?name_art='+name_art, function(data) { 
                // Place form returned via Jquery on page in formWrapper div        
                $('#formWrapper').html(data);
                $("#addRelease").validate({
                    submitHandler: function(form) {
                        form.submit();
                      }
                });
            });
            return false;
        });
    });
    
    0 讨论(0)
提交回复
热议问题