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

房东的猫 提交于 2019-12-02 01:06:14

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:

<form class="myForm">

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

ID values are unique to a single DOM element. So you'd need to give each form a new ID, so if you had three forms, you could name them like so:

<form name="formone" id="formone"...
<form name="formtwo" id="formtwo"...
<form name="formthree" id="formthree"...

Now you'd create instances of your ajax request like so:

     $('#formone, #formtwo, #formthree').ajaxForm({
       beforeSubmit: showLoader,
       success: hideLoader
     }); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!