jQuery datepicker返回"inst为null".通过AJAX加载时出错 [英] jQuery datepicker returns "inst is null" error when loaded via AJAX

查看:69
本文介绍了jQuery datepicker返回"inst为null".通过AJAX加载时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过AJAX调用将内容加载到动态添加到DOM的表行中.我在回调函数中调用了datepicker功能,日历显示正常.但是,当我单击日期时,出现错误:inst为null.这是我的代码:

I'm loading content via an AJAX call into a table row added to the DOM on the fly. I'm calling the datepicker functionality in my callback function and the calendar shows fine. However, when I click on the date, I get an error: inst is null. Here's my code:

$(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类,删除对datepicker的所有引用等,但是没有任何效果.预先感谢您的帮助!

I've tried deleting the hasDatepicker class, deleting any references to the datepicker, etc. but nothing is working. Thanks in advance for helping!

推荐答案

我遇到了相同的错误,这是因为我有两个具有相同id的datepickers输入字段,一个在运行时设置,另一个通过ajax设置. 给他们一个唯一的ID,一切正常

I had the same error, which was because I had two datepickers input fields with the same id, one setup during runtime and the other through ajax. Gave them a unique id and it all worked

这篇关于jQuery datepicker返回"inst为null".通过AJAX加载时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆