Datepicker onSelect不填充HiddenField

时间:2014-08-27 13:50:36

标签: jquery datepicker

已搜索过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");
    }

});

1 个答案:

答案 0 :(得分:0)

试试这个:

$(document).ready(function(){
$("#myDate").datepicker();
$("#myDate").change(function(){
   $("#myHidden").val($(this).val());
    alert("Hidden value: " +  $("#myHidden").val());
});
});

工作小提琴:http://jsfiddle.net/robertrozas/4nd5hL9u/1/

更新了代码:http://jsfiddle.net/robertrozas/4nd5hL9u/2/

更新

HTML:

<div class="divAndHidden">
 <input type="hidden" id="aspHidden" value="" />
</div>

Jquery的:

$(".myTextBox").datepicker({
beforeShowDay: unavailable,
onSelect: function (date) {
   alert(this.value);
    $(".divAndHidden").find(":hidden").val(this.value); 
}
});

工作小提琴:http://jsfiddle.net/robertrozas/4nd5hL9u/4/