DatePicker的不是工作的AJAX加载页面加载、页面、不是、工作

2023-09-10 13:55:44 作者:执迷不悟

我附上日期选择器来输入,在一个全球性的脚本文件是这样的:

I attach the datepicker to inputs in a global script file with like this:

$(document).on("focusin",".datePick", function () {
            $(this).datepicker({
                dateFormat: "dd/mm/yy",
                changeMonth: true,
                changeYear: true,
                onClose: function () { $(this).valid(); }
            });
        });

在一个特定的页面,有输入的模态对话框(也jQuery的用户界面)(将与日期选择器使用),我通过调用$ .load(即页面),并注入到其他网页股利。

On a specific page, there are inputs(which will be used with datepicker) in a modal dialog(also jquery ui) and I call that page via $.load() and inject into a div in other page.

在code以上的作品非常好静态输入其他页面,但对于上述之情况,它显示了日期选择器对话框罚款,但是当我点击一个日期,它会抛出错误(F是不确定的)编辑:VS2010抛出无法设置属性值CURRENTDAY:对象为null或undefined

The code above works very well for static inputs in other pages but for the scenerio above, it shows the datepicker dialog fine but when I click on a date, it throws error(f is undefined) VS2010 throws "Unable to set value of the property 'currentDay': object is null or undefined"

有些人建议住()方法来使用,但我不希望使用德precated方法..我应该怎么办这个问题?

Some people suggested to use live() method, but I dont want to use deprecated method.. What should I do about the issue?

在此先感谢

Ozgu

推荐答案

正如我在TJ VanToll的答复意见,只要到触发器绑定的父元素是present当时的DOM是加载,你会没事的。

As mentioned in my comment on TJ VanToll's answer, as long as the parent element to which your trigger is bound is present at the time the DOM is loaded, you'll be fine.

请参阅这种提琴一个例子。

JS:

$(function(){
    $(document).on("focusin",".datePick", function () {
       $(this).datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            onClose: function () { $(this).valid(); }
        });
    });

    $('#focusin').append('<input class="datePick" name="datepicker" />');

});​

HTML:

<div id="focusin"></div>​

只要你的语气DIV是负载present,它应该能够加载后捕捉到你的输入。

As long as your modal div is present on load, it should be able to capture your input after loading.