没有 jQuery 的 JavaScript 日期时间选择器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22484947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript Datetime picker without jQuery?
提问by AlexRamallo
I need to have my users select a date and time in one of my forms, and I don't want to spend time reinventing the wheel to create a datetime picker
in JavaScript. The problem is that the only "pickers" I can find online are all based on jQuery, which normally wouldn't be a problem except that the entire site is practically finished without using jQuery at all. So it would feel stupid to use that entire giant framework now when all I need it for is a single input on one form on one page of my site.
我需要让我的用户在我的一个表单中选择一个日期和时间,而且我不想花时间重新发明轮子来datetime picker
在 JavaScript 中创建一个。问题是我可以在网上找到的唯一“选择器”都是基于 jQuery 的,这通常不会成为问题,除非整个站点实际上完全没有使用 jQuery 就完成了。因此,当我只需要在我网站的一个页面上的一个表单上进行单个输入时,现在使用整个巨大的框架会感觉很愚蠢。
回答by clement
There is a datetime Picker in HTML5 but it doesn't work for all browsers. You can try this example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_date
HTML5 中有一个日期时间选择器,但它不适用于所有浏览器。你可以试试这个例子:http: //www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_date
回答by Daniel Szabo
We've been using Pikadaywith great success on our project. One of our forms has over 60 date fields on it (legal industry), and this little widget has performed very well. It's 5kb minified and highly configurable. The default styling looks pretty slick, too. One last thing I'd like to add is that Pikaday also has the ability to clean up after itself (.destroy command), which has been extremely helpful on more dynamic forms.. Many other date pickers don't clean up after themselves when the node to which they're attached is removed from the dom. Highly recommend it.
我们一直在使用Pikaday在我们的项目中取得了巨大的成功。我们的一个表单上有 60 多个日期字段(法律行业),这个小部件表现非常好。它缩小了 5kb 并且高度可配置。默认样式看起来也很漂亮。我想补充的最后一件事是 Pikaday 还具有自行清理的能力(.destroy 命令),这对更动态的表单非常有帮助。许多其他日期选择器在以下情况下不会自行清理它们所连接的节点从 dom 中删除。强烈推荐它。