Open JQuery Datepicker by clicking on an image w/ no input field

后端 未结 8 931
夕颜
夕颜 2020-11-27 13:00

I want to have the JQuery Datepicker open when the user clicks on an image. There is no input field where the selected date appears afterwards; I\'m just going to save the e

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 13:46

    Turns out that a simple hidden input field does the job:

    
    

    And then use the buttonImage attribute for your image, like normal:

        $("#dp").datepicker({
            buttonImage: '../images/icon_star.gif',
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true,
            showOn: 'both',
         });
    

    Initially I tried a text input field and then set a display:none style on it, but that caused the calendar to emerge from the top of the browser, rather than from where the user clicked. But the hidden field works as desired.

提交回复
热议问题