[英]Input formatting
I'm using an input type="number"
to allow users to put a duration time on a post. 我使用
input type="number"
允许用户在帖子上放置持续时间。 The format is days hours:minutes:seconds
as the backend provides the format. 格式为
days hours:minutes:seconds
因为后端提供了格式。
What I need to do is to give that format to the input. 我需要做的就是将该格式输入。 Is this possible?
这可能吗?
You can use input type text with pattern: 您可以将输入类型的文本与模式一起使用:
<form> <input type="text" pattern="^\\d{1,3} \\d{1,2}:\\d{1,2}:\\d{1,2}$" placeholder="days hours:minutes:seconds"/> <input type="submit"/> </form>
It will validate the text using 1-3 digits for days and 1-2 for hours minutes and seconds. 它将使用1-3位数字(几天)和1-2位(小时,分钟和秒)来验证文本。
You can also restrict typing of no digits and colons and space using jQuery: 您还可以使用jQuery限制无数字,冒号和空格的输入:
$(function() { $('input').keydown(function(e) { console.log(e.which); if (!((e.which >= 48 && e.which <= 57) || (e.which == 186 && e.shiftKey) || e.which == 32)) { return false; } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <input type="text" pattern="^\\d{1,3} \\d{1,2}:\\d{1,2}:\\d{1,2}$" placeholder="days hours:minutes:seconds"/> <input type="submit"/> </form>
If you have jQuery
, then take a look at: 如果您使用
jQuery
,那么请看一下:
http://jonthornton.github.io/jquery-timepicker/ http://jonthornton.github.io/jquery-timepicker/
你也可以使用
<input type="datetime">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.