jQuery UI日期选择器在对话框上崩溃

jQuery UI日期选择器在对话框上崩溃,jquery,ajax,jquery-ui,Jquery,Ajax,Jquery Ui,我正在加载一个带有jQuery UI和加载函数的对话框页面: $("#update_link").dialog({ modal: false, height: 370, width: 900, title: 'עדכן קישור', open: function () { $(this).load("<?= site_url()?>/links/show_update?id="+rel+"&rand="+rand()); } }); $(“

我正在加载一个带有jQuery UI和加载函数的对话框页面:

$("#update_link").dialog({
  modal: false,
  height: 370,
  width: 900,
  title: 'עדכן קישור',
  open: function () {
    $(this).load("<?= site_url()?>/links/show_update?id="+rel+"&rand="+rand());
  }
});
$(“更新链接”)。对话框({
莫代尔:错,
身高:370,
宽度:900,
标题:“עדןקישור”,
打开:函数(){
$(this).load(“/links/show_update?id=“+rel+”&rand=“+rand()”);
}
});
对话框中有一个id为“add_time”的输入文本。在此输入中有一个日期选择器:

$(".float_form[rel='<?=$id;?>'] #add_time").datepicker({
  showOn: "button",
  buttonImage: "<?=base_url()?>/images/icons/new.png",
  buttonImageOnly: true,
  onClose: function(dateText, inst) { alert("die"); }
});
$(“.float_form[rel=''']#add_time”).datepicker({
展示:“按钮”,
buttonImage:“/images/icons/new.png”,
buttonImageOnly:正确,
onClose:函数(dateText,inst){alert(“die”);}
});
当我运行它时,它第一次工作正常。然后关闭对话框并更改打开对话框的链接(使用Ajax)。如果使用日期选择器再次单击输入文本,则在控制台上会出现以下错误:

未捕获的TypeError:无法设置未定义的属性“currentDay”

由于此错误,我无法单击日期选择器中的任何日期。我做错了什么


很抱歉我的英语不好,谢谢:)

看来你把DatePicker的销毁搞砸了,下面是一个例子:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<div id="dialog" style="display:none">

</div>
<button id="ds">dialog show</button>

<script>
$(function(){$('#ds').click(function() {
    var datep = $('<input type="text" id="datep">');
    datep.datepicker();
    var dlg = $('#dialog').dialog({
        modal: false,
        open: function() {
            var e = $(this);
            e.html('');
            e.append(datep);

            console.log(datep);
        },
        close: function() {
            datep.datepicker("destroy");
        }

    });
});
});
</script>

对话节目
$(function(){$('#ds')。单击(function(){
var datep=$('');
datep.datepicker();
var dlg=$('#dialog')。dialog({
莫代尔:错,
打开:函数(){
var e=$(本);
e、 html(“”);
e、 追加(datep);
console.log(datep);
},
关闭:函数(){
日期选择器(“销毁”);
}
});
});
});


寓意:关闭对话框时使用desroy,而不是datepicker。

似乎你搞乱了datepicker的销毁,下面是一个例子:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<div id="dialog" style="display:none">

</div>
<button id="ds">dialog show</button>

<script>
$(function(){$('#ds').click(function() {
    var datep = $('<input type="text" id="datep">');
    datep.datepicker();
    var dlg = $('#dialog').dialog({
        modal: false,
        open: function() {
            var e = $(this);
            e.html('');
            e.append(datep);

            console.log(datep);
        },
        close: function() {
            datep.datepicker("destroy");
        }

    });
});
});
</script>

对话节目
$(function(){$('#ds')。单击(function(){
var datep=$('');
datep.datepicker();
var dlg=$('#dialog')。dialog({
莫代尔:错,
打开:函数(){
var e=$(本);
e、 html(“”);
e、 追加(datep);
console.log(datep);
},
关闭:函数(){
日期选择器(“销毁”);
}
});
});
});

寓意:在关闭对话框时使用desroy,而不是datepicker。

我找到了一个解决方案: 您只需将
id=“add\u time”
替换为
class=“add\u time”

代码:

我找到了一个解决方案: 您只需将
id=“add\u time”
替换为
class=“add\u time”

代码:


哪里是currentDay属性集?不是我设置的,我认为它是自动设置的。哪里是currentDay属性集?不是我设置的,我认为它是自动设置的。我不能使用此代码,因为输入文本直接取自加载函数。你知道如何使用load吗?你仍然可以,只要在对话框关闭时销毁datepicker,使用e.find()获取datepicker输入,使用JSFIDLE我不能用load()显示。在
close:function()
中,我尝试使用以下代码:
$(this)。find(.float_form[rel=“+rel+”)#add#time”)。datepicker(“销毁”)它仍然不起作用使用console.log()检查您的发现返回的内容它看起来太复杂了我明白了:
[​]
我不能使用此代码,因为输入文本直接取自load函数。你知道如何使用load吗?你仍然可以,只要在对话框关闭时销毁datepicker,使用e.find()获取datepicker输入,使用JSFIDLE我不能用load()显示。在
关闭:函数()
中,我尝试使用此代码:
$(此).find(“.float_form[rel=“+rel+”]#add_time”).datepicker(“destroy”)
它仍然无法工作使用console.log()检查您的查找结果返回的内容看起来过于复杂了我明白了:
[​]为什么会这样?为什么会这样?