dqoys62082 2015-06-09 18:57
浏览 77
已采纳

限制用户在文本字段中手动输入日期

I use a calender with text field, i want only calender selected value is inserted on text value, other keyboard manual value is not inserted on text box.

<input type="text" name="date_to" value="<?php echo $date_to; ?>" placeholder="To" id="to" class="Original-datepicker" required />

This is my code. when i click on this text box then calender is open and selected value is insert on text value. I want here only calender selected value is used here as text value. Manual value is not inserted here.

I need to restrict user for enter date manually...

i use this jquery code for both my calender or timepicker

$(document).ready(function () {
        $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            onClose: function( selectedDate ) {
                $( "#from" ).datepicker( "option", "minDate", selectedDate );
            }
        });
        $( "#from" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            onClose: function( selectedDate ) {
                $( "#to" ).datepicker( "option", "maxDate", selectedDate );
            }
        });
    });

     $(document).ready(function () {
        $('#onselectExample').timepicker({ 'timeFormat': 'h:i A','minTime': '9:00am', 'maxTime': '9:00pm', });

        $('#onselectTarget').timepicker({ 'timeFormat': 'h:i A','minTime': '9:00am', 'maxTime': '9:00pm', });
    });

i use readonly='true' like:--

" placeholder="To" id="to" class="Original-datepicker" required readonly='true' />

this help me in calender case

but in timepicker case i face same problem..

timepicker is open as dropdown and i select one time option. when i use readonly then dropdown is not open..

  • 写回答

2条回答 默认 最新

  • dqdpz60048 2015-06-09 19:11
    关注

    You may simply add readonly attribute

    <input readonly="readonly" type="text" name="date_to" value="<?php echo $date_to; ?>" placeholder="To" id="to" class="Original-datepicker" required />
    

    and for timepicker, you can simply prevent to keypress event, See Demo

    $('#onselectExample,#onselectTarget').keypress(function(event){
        event.preventDefault();});
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证