带有 type=date 的默认 HTML 输入(下面的代码)将显示日期选择器输入。
但是,只有当您单击输入框最右侧的日历图标时,日期选择器对话框才会打开。
如果您单击输入中的其他任何地方,该对话框不会打开。
当您单击输入框内的任意位置时,如何启用输入框以打开日期选择器对话框?
注意:我已经在 Stack overflow 和互联网上搜索过类似问题的答案,但没有找到合适的解决方案。
<label for="session-date">Start date:</label>
<input type="date" id="session-date" name="session-date">
单击该字段时应该这样做(没有 js!);当它第一次聚焦时,它只监听输入,但你可以使用 js 解决。
input#session-date {
display: inline-block;
position: relative;
}
input[type="date"]::-webkit-calendar-picker-indicator {
background: transparent;
bottom: 0;
color: transparent;
cursor: pointer;
height: auto;
left: 0;
position: absolute;
right: 0;
top: 0;
width: auto;
}
注意:使用这种方法你会丢失图标,但你绝对可以添加一个:
Here's the demo on codepen