I am using the Bootstrap datatimepicker ( https://eonasdan.github.io/bootstrap-datetimepicker/ ). I'd like to disable the datetimepicker on page load.
$(document).ready(function () {
$('#datetimepicker1').datetimepicker({
defaultDate: new Date(),
format: 'DD/MM/YYYY hh:mm:ss A'
});
});
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
I have tried $('#datetimepicker1').prop('disabled', true)
and $('#datetimepicker1').disable()
from ( http://eonasdan.github.io/bootstrap-datetimepicker/Functions/#disable ). Neither work. So what is the best way to do it?
try the following code $('#datetimepicker1 > .form-control').prop('disabled', true);
please check the link https://jsfiddle.net/komal10041992/DTcHh/32829/
You were close to solution, you have to use disable()
, but you have to remember that, as docs says:
Note All functions are accessed via the data attribute eg
$('#datetimepicker').data("DateTimePicker").FUNCTION()
So you have to add .data("DateTimePicker")
to your $('#datetimepicker1').disable()
.
Here a working sample:
$('#datetimepicker1').datetimepicker({ defaultDate: new Date(), format: 'DD/MM/YYYY hh:mm:ss A' }); //To Disable use disable() function $('#datetimepicker1').data("DateTimePicker").disable(); //To Enable use enable() function //$('#datetimepicker1').data("DateTimePicker").enable();
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/> <link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script> <div class='input-group date' id='datetimepicker1'> <input type='text' class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div>
$(document).ready(function () { $('#datetimepicker1').datetimepicker({ defaultDate: new Date(), format: 'DD/MM/YYYY hh:mm:ss A' }).find("input:first").prop("disabled", true); });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.