2

我在我的网页上使用 JQuery UI 的 Datepicker。目前,我已经成功地让它与一个名为“mydate”的文本字段一起工作。代码如下:

$('#releasedate').datepicker({
                changeYear: 'true',
                changeMonth:'true',
                startDate: '07/16/1989',
                firstDay: 1
            });

但是,我想要一点点改变。而不是文本字段,我想显示一个名为“选择日期”的链接,它应该打开日期选择器,并且在选择日期后,需要更新隐藏文本字段的值。

我尝试了不同的方法来做到这一点,但都没有成功。jQuery专家,你能帮帮我吗?我急切地等待收到解决方案。非常感谢您提前。

4

2 回答 2

9

您实际上可以将 datepicker 附加到 an<input type="hidden" />并使链接成为打开它的触发器:

$(function() {
    $('#hiddenDate').datepicker({
        changeYear: 'true',
        changeMonth: 'true',
        startDate: '07/16/1989',
        firstDay: 1
    });
    $('#pickDate').click(function (e) {
        $('#hiddenDate').datepicker("show");
        e.preventDefault();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>

<input id="hiddenDate" type="hidden" />
<a href="#" id="pickDate">Select Date</a>

于 2013-04-10T20:59:11.040 回答
1

尝试这个:

$('#datepicker').datepicker('hide');
$('a').click(function () {
    $('#datepicker').datepicker('destroy');
    $('#datepicker').datepicker({
        altField: '#shhh',
        changeYear: 'true',
        changeMonth: 'true',
        firstDay: 1,
        onSelect: function () {
            $('#datepicker').datepicker('destroy');
        }
    })
});

jsFiddle 示例

于 2013-04-10T21:12:59.340 回答