开发者

Remove jquery datepicker from a html control

开发者 https://www.devze.com 2023-01-21 16:24 出处:网络
I have a datepicker on a textbox txtDate. I need to remove the datepicker, if a particular checkbox chkBox is checked. And to reapply the datepicker if the checkbox开发者_如何学Go is not checked.

I have a datepicker on a textbox txtDate. I need to remove the datepicker, if a particular checkbox chkBox is checked. And to reapply the datepicker if the checkbox开发者_如何学Go is not checked.

I tried making the textbox readonly, but datepicker is still working. How to do this.

EDIT: On the same checkbox event, I also want to make a select (dropdown) control as non selectable. No one should be able to change what in the select control.


In your change handler for the checkbox you can call enable or disable on the datepicker, for example:

$("#chkBox").change(function() {
  $("#txtDate").attr("readonly", this.checked)
               .datepicker(this.checked ? "disable" : "enable");
  //for your edit:
  $("#someSelect").attr("disabled", this.checked);
});

You can try it out in a demo here.

0

精彩评论

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