$( ".datepicker_1" ).datepicker({
numberOfMonths: 2,
showButtonPanel: false,
minDate: new Date('<?php echo $st_date_sh.' '.$st_month_sh.', '.$st_year_sh?> 00:00:00'), //line 88
maxDate: new Date('<?php echo $en_date_sh.' '.$en_month_sh.', '.$en_year_sh?> 12:00:00'), //line 88
showOn: "button",
buttonImage: "images/Cal.gif",
buttonImageOnly: true,
/*beforeShowDay:function(dt){
return [(dt.getDay()==0)?false:true];
},*/
onSelect: function(dateText, inst) {
var dt_txt = dateText.replace('-','/');
dt_txt = dt_txt.replace('-','/');
var tmp_dt = new Date(dt_txt);
if(tmp_dt.getDay()==0)
{
if(confirm("Are you certain you want to assign Sunday delivery date?"))
{
//$(this).closest("tr").find(".update_quote_row").click();
}
else
{
return false;
}
}
}
});
我想要做的是,如果用户试图选择星期日,则应显示确认,并且只有在确认选择后才会填充相关的文本字段。但是,使用我的代码,无论我确认还是取消,文本字段都会更改为所选值,我需要阻止它。我也不能简单地将输入字段设置为空白,因为如果用户取消确认,可能存在不应修改的现有值。
答案 0 :(得分:0)
这是一个想法:
1. Assign your datepicker to a div. See 'Display inline' example in http://jqueryui.com/demos/datepicker/#inline
2. onclick of the input field, show the div. Make sure you copy the date (if present) in the input field to the datepicker div before show
3. Then you can select your date accordingly and the date in the input field would not change.
4. After getting your required date, click the submit button and assign the date on the datepicker to the input field and hide the div.
答案 1 :(得分:0)
您可以将textfield的先前值存储在某个变量中并相应地工作,例如:
var prevVal = $.trim( $("input.datepicker_1").val() );
$( ".datepicker_1" ).datepicker({
numberOfMonths: 2,
showButtonPanel: false,
......
onSelect: function(dateText, inst) {
var dt_txt = dateText.replace('-','/');
dt_txt = dt_txt.replace('-','/');
var tmp_dt = new Date(dt_txt);
if(tmp_dt.getDay()==0) {
if(confirm("Are you certain you wa...")) {
return true;
}
else {
//show previous value
$(".datepicker_1").val(prevVal);
}
.........
希望有所帮助