简体   繁体   English

HTML5输入类型=日期:我可以用JavaScript打开/关闭日期选择器吗?

[英]HTML5 input type=date: Can I open/close the date picker with JavaScript?

I am trying to customise the HTML5 input type="date" element. 我正在尝试自定义HTML5 input type =“date”元素。 I want to add a separate button clicking which will toggle visibility of the date picker dropdown. 我想添加一个单独的按钮,它将切换日期选择器下拉列表的可见性。 I couldn't find any info on this. 我找不到任何关于此的信息。 Any help greatly appreciated! 任何帮助非常感谢!

在此输入图像描述

Here is Solution I made using CSS. 这是我使用CSS制作的解决方案。

 * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .exmp-wrp { margin-top: 100px; position: relative; width: 200px; } .btn-wrp { border: 1px solid #dadada; display: inline-block; width: 100%; position: relative; z-index: 10; } .btn-clck { border: none; background: transparent; width: 100%; padding: 10px; } .btn-clck::-webkit-calendar-picker-indicator { right: -10px; position: absolute; width: 78px; height: 40px; color: rgba(204, 204, 204, 0); opacity: 0 } .btn-clck::-webkit-inner-spin-button { -webkit-appearance: none; } .btn-clck::-webkit-clear-button { margin-right:75px; } .btn { height: 100%; background: #fda200; border: none; color: #fff; padding: 13px; position: absolute; right: 0; top: 0; } 
 <div class="exmp-wrp"> <div class="btn-wrp"> <input type="date" class="btn-clck"/> </div> <button class="btn">Click me</button> </div> 

Try this one: 试试这个:

$(document).ready(function () {
    $('input[type="date"]').change(function () {
        closeDate(this);
    });

});

function closeDate(dateInput) {
    $(dateInput).attr('type', 'text');
    $(dateInput).attr('type', 'date');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM