How to make AjaxForm work with several forms loaded using jquery load()?

前端 未结 2 352
花落未央
花落未央 2021-01-22 18:44

I have a page with a div that is dynamically filled using a paginator ;-) At page init I load the first 10 forms in it using jquery .load() method.

What I\'d like to do

2条回答
  •  佛祖请我去吃肉
    2021-01-22 19:00

    I'll try and address these one at a time to better match the question:

    1) You can re-bind when you .load() (or whatever jQuery ajax method you're using) or use a plugin like livequery(), for example here's re-binding (do this in your success handler):

    $("#myDynamicDiv .myForm").ajaxForm({ ...options... }); 
    

    Or using livequery():

    $(".myForm").livequery(function() { $(this).ajaxForm({ ...options... }); });
    

    2) Use a class instead of IDs here, like this: class="myForm", whenever you want to handle batches of elements like this class is a pretty safe route. The examples above work with class and not IDs per form (they can have IDs, they're just not used). Your form tags would look like this:

    3) The same solutions in answer #1 account for this :)

提交回复
热议问题