gpt4 book ai didi

javascript - 从 jquery datepicker 选择日期后关闭 jquery 对话框

转载 作者:行者123 更新时间:2023-11-28 05:49:39 26 4
gpt4 key购买 nike

我的问题是我有 jquery 对话框。在对话框内,我正在填充一个输入框并初始化日期选择器,它可以选择选择日期然后完成按钮。

我希望当我选择日期并单击“完成”时,对话框也应该与日期选择器一起关闭。

<script>
$(document).ready(function() {
$('body').on('click','[id^="trnids"]',function(){
vartrnnum = $(this).text();
vartrnname = $(this).closest('#alstn > tr').find('.clstrnname').text();

document.getElementById('divnewdate').innerHTML = ("<input id='ipnewdoj'>");

fulldate1 = fulldate;
datearray1 = fulldate1.split("-"); //storing dd,mm,yy seperated by "-" or "/"
vardoj1 = datearray1[2] + datearray1[1] + datearray1[0]; //joining yyyymmdd

document.getElementById("ipnewdoj").value = vardoj1;

$(function() {
$('#ipnewdoj').datepicker( {
onSelect: function(date) {
vardoj1 = date;
},
dateFormat: 'yymmdd', //you can modify this - in lower case dd-mm-yy
numberOfMonths: 1,
showButtonPanel: true,
showWeek: true,
firstDay: 1,
changeMonth: true,
changeYear: true,
showAnim: 'fold', //show; slideDown; fadeIN; blind; bounce, drop; fold; clip;
minDate: '-4D', //min days calender will go back. use '-12D' for days, '-12W' for weeks, '-12M' for months, or '-12Y' for years.
maxDate: '0D', //max days calender will go next. use '+12D' for days, '+12W' for weeks, '+12M' for months, or '+12Y' for years.
}).val();
});

$(function() {
$("#divnewdate").dialog({
width: 250,
height: 270,
modal: true,
dialogClass:'datagrid',
show: {effect: "clip", duration: 1000},
hide: {effect: "drop", duration: 200},
close: function( event, ui ) {
fnltrs();//write your function here or call function here
}//dialog box close option end
}); // dialog } close
}); // dialog function } close


}); //main click event close fn
}); // document ready fn close

</script>

非常感谢任何帮助。

最佳答案

尝试下面的代码。

$(document).ready(function() { 
$('body').on('click','[id^="trnids"]',function(){
vartrnnum = $(this).text();
vartrnname = $(this).closest('#alstn > tr').find('.clstrnname').text();

document.getElementById('divnewdate').innerHTML = ("<input id='ipnewdoj'>");

fulldate1 = fulldate;
datearray1 = fulldate1.split("-"); //storing dd,mm,yy seperated by "-" or "/"
vardoj1 = datearray1[2] + datearray1[1] + datearray1[0]; //joining yyyymmdd

document.getElementById("ipnewdoj").value = vardoj1;

$(function() {
$('#ipnewdoj').datepicker( {
onSelect: function(date) {
vardoj1 = date;
},
onClose: function () { // Note this additional function here
$('#divnewdate').dialog('close');
},
dateFormat: 'yymmdd', //you can modify this - in lower case dd-mm-yy
numberOfMonths: 1,
showButtonPanel: true,
showWeek: true,
firstDay: 1,
changeMonth: true,
changeYear: true,
showAnim: 'fold', //show; slideDown; fadeIN; blind; bounce, drop; fold; clip;
minDate: '-4D', //min days calender will go back. use '-12D' for days, '-12W' for weeks, '-12M' for months, or '-12Y' for years.
maxDate: '0D', //max days calender will go next. use '+12D' for days, '+12W' for weeks, '+12M' for months, or '+12Y' for years.
}).val();
});

$(function() {
$("#divnewdate").dialog({
width: 250,
height: 270,
modal: true,
dialogClass:'datagrid',
show: {effect: "clip", duration: 1000},
hide: {effect: "drop", duration: 200},
close: function( event, ui ) {
fnltrs();//write your function here or call function here
}//dialog box close option end
}); // dialog } close
}); // dialog function } close


}); //main click event close fn
}); // document ready fn close

此代码确保每当日期选择器关闭时,它也会关闭对话框。

关于javascript - 从 jquery datepicker 选择日期后关闭 jquery 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38182726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com