已搜索过SO以寻求解决方案,但所有示例似乎都无法解决我的问题。以下是推荐的方法,这适用于一个小项目,但失败了我的例子。还查看了Datepicker小部件文档,onSelect不是很有帮助:
$('.myTextBox').datepicker();
$('.myTextBox').datepicker("option", "onSelect", function(){alert('hi')});
这是我的代码:
function noWeekEnds(date) {
var kelly = ($(".myKelly").val()) - 1;
var dow = date.getDay();
if(dow==kelly) return [false,''];
return [true,''];
}
function unavailable(date) {
var now = date;
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var nwe = noWeekEnds(date);
var Ashift = (day%3===2) && nwe[0]; // A Shift
var Bshift = (day%3===0) && nwe[0]; // B Shift
var Cshift = (day%3===1) && nwe[0]; // C Shift
return [Cshift, "redback", "available"];
}
$(".myTextBox").datepicker({
beforeShowDay: unavailable,
onSelect: function (date) {
alert("works");
}
});
答案 0 :(得分:0)
试试这个:
$(document).ready(function(){
$("#myDate").datepicker();
$("#myDate").change(function(){
$("#myHidden").val($(this).val());
alert("Hidden value: " + $("#myHidden").val());
});
});
<div class="divAndHidden">
<input type="hidden" id="aspHidden" value="" />
</div>
$(".myTextBox").datepicker({
beforeShowDay: unavailable,
onSelect: function (date) {
alert(this.value);
$(".divAndHidden").find(":hidden").val(this.value);
}
});