jQuery: enabling/disabling datepicker

前端 未结 18 994
青春惊慌失措
青春惊慌失措 2020-12-03 06:38

In my php-file, I want to use the jQuery Datepicker.

When my file loads, I create the Datepicker disabled.

Then, when a special field in my php-file (it is a

相关标签:
18条回答
  • 2020-12-03 06:56

    Also set the field to disabled when you disable the datePicker e.g

    $("input").prop('disabled', true);
    

    To stop the image being clickable you could unbind the click event on that

    $('img#<id or class ref>').unbind('click');
    
    0 讨论(0)
  • 2020-12-03 06:58

    Try something like this it will help you

    $("#from").click(function () {
               $('#from').attr('readonly', true);
         });
    

    Thanks

    0 讨论(0)
  • 2020-12-03 06:59

    simply use the following code

    $("#from").datepicker({
     showOn: "off"
    });
    

    it will not show the display of datepicker

    0 讨论(0)
  • 2020-12-03 06:59

    This works for me on toggling enable and disable datepicker of JQuery:

    if (condition) {
              $('#ElementID').datepicker(); //Enable datepicker                   
    } else {
             //Disable datepicker without the ability to enter any character on text input
              $('#ElementID').datepicker('destroy');
              $('#ElementID').attr('readonly', true); }
    

    I don't know why but when I use enable/disable in datepicker options, it doesn't behave the way it should be. It only works after you enable and disable it, but once you disable it, it doesn't enable again after, so the code above works perfectly fine for me:

    if (condition) {
          $('#ElementID').datepicker('enable'); //Enable datepicker                   
    } else {
          //Disable datepicker but I cannot enable it again once it goes through this condition
          $('#ElementID').datepicker('disable');  }
    
    0 讨论(0)
  • 2020-12-03 07:00

    try

    $("#from").datepicker().datepicker('disable');
    
    0 讨论(0)
  • 2020-12-03 07:01
    $("#nicIssuedDate").prop('disabled', true);
    

    This is works 100% with bootstrap Datepicker

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