本文介绍了如何限制用户使用datetimepicker输入数据并禁用手动用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想限制用户仅使用datetimepicker输入数据.下面是我正在使用的代码:
I want to restrict the user to only input data using the datetimepicker. Below is the code I am using:
<div class="form-group">
<label>Start</label>
<div class="input-group date" id="dtp1">
<input type="text" id="txtStart" class="form-control" readonly="readonly"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
$('#dtp1').datetimepicker({
format: 'DD/MM/YYYY HH:mm A',
daysOfWeekDisabled: [0, 6]
});
我尝试使用readonly属性,但是这同时禁用了输入和datetimepicker.有什么方法可以禁用输入字段,但仍然允许用户单击日历图标来选择日期?
I have tried using the readonly attribute, but this disables both the input and datetimepicker. Is there any way through which I can disable the input field but still allow the user to click on the calendar icon to pick a date?
推荐答案
我现在唯一想到的方法是在输入的keydown事件上使用event.preventDefault()
:
The only way I could think of right now is to use the event.preventDefault()
on the keydown event on the input:
<input type="text" id="txtStart" class="form-control" onkeydown="event.preventDefault()">
这篇关于如何限制用户使用datetimepicker输入数据并禁用手动用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!