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

后端 未结 8 897
夕颜
夕颜 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:25
    <img src='someimage.gif' id="datepicker" />
    <input type="hidden" id="dp" />
    
     $(document).on("click", "#datepicker", function () {
       $("#dp").datepicker({
        dateFormat: 'dd-mm-yy',
        minDate: 'today'}).datepicker( "show" ); 
      });
    

    you just add this code for image clicking or any other html tag clicking event. This is done by initiate the datepicker function when we click the trigger.

    0 讨论(0)
  • 2020-11-27 13:41

    To change the "..." when the mouse hovers over the calendar icon, You need to add the following in the datepicker options:

        showOn: 'button',
        buttonText: 'Click to show the calendar',
        buttonImageOnly: true, 
        buttonImage: 'images/cal2.png',
    
    0 讨论(0)
  • 2020-11-27 13:42

    If you are using an input field and an icon (like this example):

    <input name="hasta" id="Hasta"  type="text" readonly  />
    <a href="#" id="Hasta_icono" ></a>
    

    You can attach the datepicker to your icon (in my case inside the A tag via CSS) like this:

    $("#Hasta").datepicker();
      $("#Hasta_icono").click(function() { 
       $("#Hasta").datepicker( "show" );
      });
    
    0 讨论(0)
  • 2020-11-27 13:42

    HTML:

    <div class="CalendarBlock">
        <input type="hidden">
    </div>
    

    CODE:

    $CalendarBlock=$('.CalendarBlock');
    $CalendarBlock.click(function(){
        var $datepicker=$(this).find('input');
        datepicker.datepicker({dateFormat: 'mm/dd/yy'});
        $datepicker.focus(); });
    
    0 讨论(0)
  • 2020-11-27 13:46

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

    <input type="hidden" id="dp" />
    

    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.

    0 讨论(0)
  • 2020-11-27 13:47
    $(function() {
       $("#datepicker").datepicker({
           //showOn: both - datepicker will come clicking the input box as well as the calendar icon
           //showOn: button - datepicker will come only clicking the calendar icon
           showOn: 'button',
          //you can use your local path also eg. buttonImage: 'images/x_office_calendar.png'
          buttonImage: 'http://theonlytutorials.com/demo/x_office_calendar.png',
          buttonImageOnly: true,
          changeMonth: true,
          changeYear: true,
          showAnim: 'slideDown',
          duration: 'fast',
          dateFormat: 'dd-mm-yy'
      });
    });
    

    The above code belongs to this link

    0 讨论(0)
提交回复
热议问题