如何在链接点击时显示 jquery datepicker?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5082204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:32:34  来源:igfitidea点击:

How to display jquery datepicker on link click?

jqueryhyperlinkonclickdatepicker

提问by Burjua

I need to show jquery datepickeron link click, also when a date is picked change link text to this date, how can I do it?

我需要jquery datepicker在链接点击时显示,当时挑选日期的日期更改为此日期,我该如何做到?

回答by DigitalDan

jQuery UI date pickershould do the job.

jQuery UI 日期选择器应该可以完成这项工作。

Check out the example using an icon to trigger the picker: http://jqueryui.com/demos/datepicker/#icon-trigger

查看使用图标触发选择器的示例:http: //jqueryui.com/demos/datepicker/#icon-trigger

You can also call the show() method to drop down the picker whenever you need to, e.g...

您还可以在需要时调用 show() 方法来下拉选择器,例如..

$('#mypicker').datepicker({
      //options
      minDate: '20.04.2012'
      //...
    });
$('#mylink').click(function(){
      $('#mypicker').datepicker('show');
    });

To change the link text after a date is selected, use something like this in initialization code:

要在选择日期后更改链接文本,请在初始化代码中使用以下内容:

$('#mypicker').datepicker({ onSelect:
    function(dateText, inst) {
        $('#mylink').text(dateText);
    }
});

回答by slashka

Well, may be it's to late to reply in this post, but here is a great solution from Andrewin a similar thread, which works in 2015.

好吧,在这篇文章中回复可能为时已晚,但这是安德鲁在类似主题中的一个很好的解决方案,该解决方案在 2015 年有效。

In a few words you need to put hidden input right after link and an empty div. The last one will do the trick.

简而言之,您需要在链接和一个空的 div 之后放置隐藏的输入。最后一个可以解决问题。

Besides, there will no need in link click event.

此外,不需要链接点击事件。

回答by Girish

$("#dateField").datepicker({
 dateFormat:'dd/M/yy',
 minDate: 'now',
 changeMonth:true,
 changeYear:true,
 showOn: "focus",
 //buttonImage: "YourImage",
 buttonImageOnly: true, 
 yearRange: "-100:+0",  
}); 

$("dateField").datepicker( "option", "disabled", true );

回答by Bruno Serralheiro

This worked for me. Needs jquery-ui .ls and .css.

这对我有用。需要 jquery-ui .ls 和 .css。

 $( function() {
            $( "#from" ).datepicker({
                changeMonth: true,
                changeYear: true
            });
            $( "#to" ).datepicker({
                changeMonth: true,
                changeYear: true
            });

回答by Alireza Balvardi

Salam

萨拉姆

I discover this solotion :

我发现这个 solotion :

onclick="jQuery('#elementid').datetimepicker();jQuery('#elementid').datetimepicker('show');"

And work properly.

并正常工作。

Sincerely yours.

您忠诚的。

Alireza Balvardi

阿里雷萨·巴尔瓦迪