0

我只是对 jQuery 不够熟悉,无法使其正常工作。使用 jQuery Datepicker 插件,并且已经有了一些帮助,我让它工作,除了用选定的工作日值更新隐藏的输入元素。我尝试过的一切都会干扰 Datepicker 插件的功能。欢迎任何帮助。

<html>
<head>

<script src="../js/jquery.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<title> jquery date picker </title>

<script type="text/javascript">
$(function () {
  $("#Datepicker").datepicker();
});
</script>

<script type="text/javascript">
function pickdate() {
    var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
    var selecteddate = $("#Datepicker").datepicker('getDate');
    $('#Datepickerday').html(days[selecteddate.getDay()]);

    // also needs to update hidden input 'weekday' with day of week

}
</script>

</head>
<body>

Date:&nbsp;&nbsp;<input type="text" name="Datepicker" id="Datepicker" class="Datepicker" onchange="pickdate();">
<br><br>
Day:&nbsp;<span id="Datepickerday"></span>

<input type="hidden" name="weekday" id="weekday">

</body>
</html>
4

1 回答 1

1

用于.val()填写隐藏的输入。

function pickdate() {
    var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
    var selecteddate = $("#Datepicker").datepicker('getDate');
    var weekday = days[selecteddate.getDay()];
    $('#Datepickerday').html(weekday);
    $('#weekday').val(weekday);

}

或者使用 datepicker 的选项:

$("#Datepicker").datepicker( {
    altField: 'weekday',
    altFormat: 'DD',
    onSelect: function(datestring, dp) {
        var selecteddate = dp('getDate');
        $("#Datepickerday").text($.datepicker.formatDate(selecteddate, 'DD'));
    }
});
于 2013-07-23T17:17:46.560 回答