jQuery: enabling/disabling datepicker

前端 未结 18 995
青春惊慌失措
青春惊慌失措 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 07:11

    Well You can remove datepicker by simply remove hasDatepicker class from input.

    Code

    $( "#from" ).removeClass('hasDatepicker')
    
    0 讨论(0)
  • 2020-12-03 07:12

    This is what worked for me

    $("#from").attr("disabled", true);
    
    0 讨论(0)
  • 2020-12-03 07:14

    You can replace form field with its copy:

    var copy = $('#from').clone(); $('#from').replaceWith(copy);

    And after that initialize datetimepicker again.

    0 讨论(0)
  • 2020-12-03 07:18

    Datepicker is disabled automatically when the input text field is made disabled or readOnly:

    $j("#" + CSS.escape("${status.expression}")).datepicker({
        showOn: "both",
        buttonImageOnly: true,
        buttonImage: "<c:url value="/static/js/jquery/1.12.1/images/calendar.gif"/>",
        dateFormat: "yymmdd",
        beforeShow: function(o, o2) {
        var ret = $j("#" + CSS.escape("${status.expression}")).prop("disabled")
            || $j("#" + CSS.escape("${status.expression}")).prop("readOnly");
    
        if (ret){
            return false;
        }
    
        return o2;
    }
    });
    
    0 讨论(0)
  • 2020-12-03 07:21
    $('#ElementID').unbind('focus');
    

    did the trick for me !!

    0 讨论(0)
  • 2020-12-03 07:21
       $("#datepicker").datepicker({
         dateFormat:'dd/M/yy',
         minDate: 'now',
         changeMonth:true,
         changeYear:true,
         showOn: "focus",
        // buttonImage: "YourImage",
         buttonImageOnly: true, 
         yearRange: "-100:+0",  
      }); 
    
      $( "#datepicker" ).datepicker( "option", "disabled", true ); //missing ID selector
    
    0 讨论(0)
提交回复
热议问题