2010-03-03 55 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

相关问题