我如何创建一个选择日期的日历图标,但是在纯JavaScript/html/css中不显示输入?
我的目标
可用的内容
” ://i.sstatic.net/gxc5i.png“ alt =“在此处输入图像说明”>
这是使用简单的日历输入完成的。
<input type="date">
我尝试减少输入的宽度,但是随着它在不同的浏览器中变形,它似乎并不优雅。以前的图像在铬上。以下是在Mozilla中出现的方式。
我认为我可以为每个浏览器指定宽度。然而,这似乎不高档而令人费解。
My goal
What is available
This is done using a simple calendar input.
<input type="date">
I have tried reducing the width of the input, but then it doesn't seem elegant as it deforms in different browsers. The previous images were on chrome. Below is how it appears in Mozilla.
I think I could specify the width for each browser. That however seems inelegant and convoluted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在大多数现代浏览器您可以使用
showpicker()
输入[type = date]
元素以使小部件出现。因此,考虑到这一点,您可以将
&lt; input&gt;
移动到带有溢出的容器之外:隐藏
,然后从中触发小部件。 >事件在另一个元素上。
像下面的摘要一样工作的类似,尽管由于有限的支持,我并不建议在公共面对的Web应用程序中使用它:
In most modern browsers you can use the
showPicker()
method of aninput[type=date]
element to make the widget appear.So, with that in mind, you could move the
<input>
outside of a container withoverflow:hidden
and trigger the widget from aclick
event on another element.Something like the snippet below might work, though I wouldn't really suggest using this in a public facing web app due to the limited support :
Instead, I would recommend you look into other (more mature) options like Smart HTML Calendar which is a Custom HTML Element.
您试图实现的目标是在每个浏览器的一个解决方案中都无法做到的,因为浏览器呈现“日期”输入类型,并且每个人都有自己的有关如何渲染事物的规范。您可以尝试使用自定义组件或插件,该组件或插件使用JavaScript/CSS/HTML呈现日历,这是在不同浏览器中保持一致外观和感觉的唯一方法。
What are you trying to achieve is not possible to do in one solution for every browser because the "date" input type is rendered by the browser and every one of them has their own specification on how to render things. You could try to use a custom component or plugin that renders a calendar using javascript/CSS/HTML that is the only way to have a consistent look and feel across different browsers.