【问题标题】:html time validation to return an error message if a time before the current time is inputted如果输入当前时间之前的时间,则html时间验证返回错误消息
【发布时间】:2016-09-07 03:19:32
【问题描述】:

这是我的 html 部分时间-<input type=time name=DPTime required id=time>

这是当时的java脚本函数

function checkTime(){
                       var check=document.getElementById(time);

                   }

如果给定的输入时间早于当前时间,我不明白如何访问输入时间变量以编写 checkTime 函数来重新调整错误消息!请帮助我一整天都在考虑这个问题,但无法为该函数开发成功的算法。

【问题讨论】:

    标签: javascript html validation time


    【解决方案1】:

    可以访问元素的value

    document.getElementById('time').value 将包含时间值的字符串。然后你可以解析那个时间(我推荐使用 moment.js)并检查它。

    这是一个带有更好示例的代码笔

    http://codepen.io/kognate/pen/dpoPaB

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-07
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多