[英]Validating time entered into textbox
I have a textbox in which user can enter time (eg: 01:00) and also a drop down box for entering AM/PM fields. 我有一个文本框,用户可以在其中输入时间(例如:01:00),还有一个下拉框,用于输入AM / PM字段。 (Since the AM/PM field is used, 12-hour time format is used.)
(由于使用了AM / PM字段,所以使用了12小时制。)
The text box allows a max entry of 5 chars only (eg: 01:00). 该文本框最多只能输入5个字符(例如:01:00)。
:
, so that the user simply has to enter only the time. :
,以便用户仅需输入时间即可。 Any help would be appreciated. 任何帮助,将不胜感激。
onkeypress
code that returns false when the key pressed is not a number thus allowing only digits. onkeypress
代码,当所按的键不是数字时,该键返回false,从而仅允许数字。 onblur
event, if the value is less than 10 add zero in the beginning. onblur
事件中完成,如果该值小于10,请在开头添加零。 %
operator. %
运算符。 document.getElementById("textbox2").value = strAppendedText;
That's the general idea, let me know if you need help implementing something best give it a try yourself first. 这是一般的想法,如果您需要帮助以最好的方式实施某些东西,请先尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.