2010-03-03 54 views
1

我通過AJAX調用將內容加載到添加到DOM上的錶行中。我在回調函數中調用日期選擇器功能,日曆顯示正常。但是,當我點擊日期時,出現錯誤:inst爲空。這裏是我的代碼:當通過AJAX加載時,jQuery datepicker返回「inst is null」錯誤

$(document).ready(function() { 
    $(".edit").live("click", function() { 
     //Delete previously loaded edit row 
     $("#tempEditRow").remove(); 

     //Get the record id of the row to be edited 
     var recordID = $(this).parent("td").parent("tr").attr("id"); 

     //Add the new row to the document 
     $(this).parent("td").parent("tr").after("<tr id=\"tempEditRow\"><td id=\"tempEditCell\" colspan=\"100\"></td></tr>") 

     //Get a reference to the new row 
     var container = $("#tempEditCell"); 

     //Populate the container 
     populateContainer("/wpm/includes/ajax_editApplication.cfm?id=" + recordID, container); 
    }); 
}); 

function populateContainer(ajaxUrl, container) { 
    //Populate the container 
    $.ajax({ 
     url: ajaxUrl, 
     cache: false, 
     success: function(html){ 
      $(container).html(html); 
      $('.datepicker').datepicker(); 
     } 
    }); 
} 

我試着刪除hasDatepicker類,刪除任何引用到日期選擇器等,但沒有什麼工作。預先感謝您的幫助!

回答

5

我有同樣的錯誤,這是因爲我有相同的id 2個datepickers輸入字段,在運行時一個設置和其他通過Ajax。 給他們一個獨特的身份證,它一切工作

+0

這是問題...我在頁面中有重複的ID,與運行時加載的情況相同,另一種情況是通過ajax。 – Robert 2010-05-19 14:39:23

+0

很高興你把它排序 – andyface 2010-05-20 10:45:54

0

嘗試調用datepicker('destroy')作爲清除前一行的一部分(在remove()調用之前執行)。

$("#tempEditRow .datepicker").datepicker('destroy'); 
$("#tempEditRow").remove(); 
+0

謝謝詹姆斯。需求發生變化,日期字段出現在佈局中,因此我無法確認這會解決問題。希望這可以幫助別人。 – Robert 2010-03-26 14:19:30

相關問題