通过单击链接打开Datepicker [英] Open Datepicker by clicking a Link

查看:160
本文介绍了通过单击链接打开Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using JQuery UI's Datepicker on my web page. Currently, I have been successful in getting it to work with a textfield called "mydate". The code is as follows:

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

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

However, I want a small change. Instead of the text field, I would like to display a link called "Select Date" which should open the datepicker, and upon selecting a date, a hidden text field's value needs to be updated.

我尝试了不同的方法来做,但是不成功。 JQuery专家,你能帮我吗?我急切地等待为此接收一个解决方案。非常感谢。

I tried different ways to do it, but have been unsuccessful. JQuery experts, can you please help me? I am eagerly waiting to receive a solution for this. Thank you very much in advance.

推荐答案

您可以将日期选择器附加到< input type =hidden/> ,并使链接成为触发器以打开它:

You can actually just attach the datepicker to an <input type="hidden" /> and make the link a trigger to open it:

$(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>

这篇关于通过单击链接打开Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆