jQuery的:绑定当作ajaxForm到一个页面上的表单,通过.load加载()表单、绑定、加载、页面

2023-09-10 17:01:11 作者:兜里有糖,心里不慌

我使用的是当作ajaxForm jQuery插件来提交表单上我的Web应用程序。然而,在应用程序的一部分,我加载一些内容通过jQuery的.load thathas表格就可以了()

I'm using the ajaxForm plugin for jQuery to submit forms on my webapp. However, in one part of the app, I'm loading some content thathas a form on it via jQuery's .load()

问题在于,我不能当作ajaxForm绑定到通过AJAX加载的形式。

The problem lies in that I can't get ajaxForm to bind to the form loaded via ajax.

我已经试过这code无济于事:

I've tried this code to no avail:

 $('#viewRecordBtn').live('click', function() { // Handle the event when the 'view record' button is clicked
    $("#tab2").load('ajax/viewRecord.php'); // Load the record and the form into tab 2
    $('#formAddRecord').ajaxForm(formAddRecordOptions); // Bind the form
 });

任何帮助,真是AP preciated !!

Any help is REALLY appreciated!!

编辑:谢谢你们!这完美的作品。

Thanks guys! This works perfectly.

推荐答案

我觉得你应该把约束code到一个回调,因为负载是异步的:

I think you should put binding code into a callback, because the load is asynchronous:

 $('#viewRecordBtn').live('click', function() { // Handle the event when the 'view record' button is clicked
    $("#tab2").load('ajax/viewRecord.php', function() {
                    $('#formAddRecord').ajaxForm(formAddRecordOptions); // Bind the form
               }); // Load the record and the form into tab 2    
 });