jQuery UI datepicker display without action

拟墨画扇 提交于 2019-12-20 01:06:25

问题


Is it possible to display jQuery UI datepicker without having to click on anything? I want the datepicker to be visible when the window loads. Or is this not possible? If not is there another plugin for this or is it best to create a new on my own?


回答1:


one thing you could do is give focus to the input so that the datepicker shows:

 $('#datepicker').focus()

look here http://jsbin.com/agazes/edit#preview

or show it after creating it:

 $('#datepicker').datepicker('show')

http://jsbin.com/agazes/2/edit#preview




回答2:


This does not seem to be possible by passing an option. However, you can call the show method after creating your datepicker:

$(document).ready(function() {
    $("#yourElement").datepicker({
        // your options...
    }).datepicker("show");
});



回答3:


http://jqueryui.com/demos/datepicker/#method-show

You could call the show method when you want it to open.




回答4:


In Some jQuery versions show is not available, in that case use:

      window.addEventListener('load', function () {
        document.getElementById('datepicker').click();

     });
    jQuery(document).ready(function() {
             $('#datepicker').bind('touchstart click', function(){
                    $(this).focus();
                 });
     });


来源:https://stackoverflow.com/questions/7232250/jquery-ui-datepicker-display-without-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!