开发者

Disable a jqueryui datepicker

I have a jqueryui datepicker associated with a input text. When i make the input textbox readonly i dont want the datepicker to show up . Is that possible? I would be setting the readonly property to true or false from the code.

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
开发者_JAVA百科    </script>



<div class="demo">

<p>Date: <input type="text" id="CompleteDate"> <input class="change" type="checkbox" name="chkBoxb" id="chkBoxb"> </p>

</div>


j$('#chkBoxb').click(function(){
   var paramChangeBoxes = j$('input:checkbox.change');

 if (j$(this).is(':checked')) {

  paramChangeBoxes.removeAttr('checked');
    j$('#chkBoxb').attr('checked', 'checked');

     j$('#CompleteDate').attr('readonly',false);
     j$("#CompleteDate").datepicker();


 }
 else
 {
  j$('#CompleteDate').attr('readonly',true);
 $( "#CompleteDate:not([readonly])"  ).datepicker();
 }

});

Updated the code


disable it like this:

$('#dateSelector').datepicker('disable');

and enable it like this:

$('#dateSelector').datepicker('enable');

Here's a working sample: http://jsfiddle.net/CG64h/8/


I ran into this today and unfortunately, the answers provided above did not work. Read the datepicker code, here's how it's done in jqueryui 1.10:

$(selector).datepicker("option", "disabled", true);


Here you go:

<div class="demo">
  <p>Date: <input type="text" id="CompleteDate"> <input class="change" type="checkbox" name="chkBoxb" id="chkBoxb"> </p>
</div>

<script>
  $('#chkBoxb').click(function(){
   if ($(this).is(':checked')) {
     $('#CompleteDate').attr('readonly',false)
       .datepicker();
   } else {
     $('#CompleteDate').attr('readonly',true)
       .datepicker("destroy");
   }
  });
</script>


http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDisabled.html


I believe you should use 2 different textbox's and toggle them as needed so that only one is shown at a time. The first one as plain text box and the second one with jquery Datapicker applied.


if($("#").attr("enabled")=="false") {
  $("#").attr("disabled","true");
}


Just change the selector and add :enabled

 $( "#datepicker:enabled" ).datepicker();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜