2015-03-31 136 views
0

我正在使用AJAX從php頁面加載一些東西。這工作正常。獲取通過AJAX加載的元素?

但現在我需要獲取使用AJAX加載的元素(按鈕或窗體或div)。

我當前的代碼不工作是這樣的:

jQuery(document).ready(function() { 


$(function(){ 
    $('.delForm').on('submit', function(dleItem){ 


     // prevent native form submission here 
     dleItem.preventDefault(); 

     // now do whatever you want here 


     $.ajax({ 
      type: $(this).attr('method'),// <-- get method of form 
      url: $(this).attr('action'), 
      //url: "cart.php", 
      data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file 
      beforeSend: function(){ 

      }, 
      success: function(data){ 

      } 
     }); 
    }); 


    }); 
    }); 

我試圖做這樣的事情:

document($('.delForm')).on('submit', function(dleItem){ 

這:

body($('.delForm')).on('submit', function(dleItem){ 

但這種意志停止我的代碼工作。

可能有人請告知這個問題?

在此先感謝。

+0

有沒有'文件()'或'體()'方法,除非你寫一個或包含了一些庫。你也有一個現成的方法包裝在一個現成的方法。沒有意義。 'jQuery(document).ready(function(){})'與'$(function(){})是一樣的' – epascarello 2015-03-31 13:27:08

回答

2

使用

$(document).on('submit', '.delForm', function(dleItem) {}); 
+0

我的不好,我有一個錯字。它現在工作正常。非常感謝。 – TERO 2015-03-31 13:28:49

+0

不客氣。如果它符合您的要求,請隨時接受答案。 – D4V1D 2015-03-31 13:29:11

+0

當然,它說我需要等待2分鐘。我會在2分鐘後立即接受它。 – TERO 2015-03-31 13:30:28

相關問題