【问题标题】:Input type date输入类型日期
【发布时间】:2020-04-01 18:01:20
【问题描述】:

我想这样做:

用按钮控制输入类型日期打开日历选择日期,但输入字段无法显示。
并且选择日期的结果将显示在另一个div中(这部分已解决)。

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

    var outputDate = (this.value);
    $("#target").text(outputDate);
  });
});
input[type="date"]{opacity:0;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<label for="test1"  style="width:100px; height:100px; background:red;display:inline-block;">
<input id="test1" type="date" style="width:100px; height:100px;>
</label>
<p id="target"></p>

【问题讨论】:

    标签: javascript html css date input


    【解决方案1】:

    $(document).ready(function() {
        $('input[type="date"]').change(function() {
            var outputDate = (this.value);
            $("#target").text(outputDate);
        });
    });
    input[type="date"]{
        opacity:1;
        position: relative;
        color: transparent;
        border: none;
        background-color: red;
    }
    
    input[type="date"]::-webkit-calendar-picker-indicator {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        -webkit-appearance: none;
    }
    
    input[type="date"]::-webkit-calendar-picker-indicator:hover {
        background-color: transparent;
    }
    
    input[type="date"]::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }
    
    input[type="date"]::-webkit-datetime-edit {
        opacity: 0;
        -webkit-appearance: none;
    }
    
    input[type="date"]::-webkit-clear-button {
        background: none;
        -webkit-appearance: none;
     }
    
    label {
        position: relative;
        overflow: hidden
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <label for="test1"  style="width:100px; height:100px; background:red;display:inline-block;">
    <input id="test1" type="date" style="width:100px; height:100px;">
    </label>
    <p id="target"></p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 2021-02-03
      • 2015-11-17
      • 2018-08-15
      • 2016-05-22
      • 1970-01-01
      • 2015-11-29
      相关资源
      最近更新 更多