How display only years in input Bootstrap Datepicker?

后端 未结 6 1070
谎友^
谎友^ 2021-01-30 21:06

I am using the following code to display only the years:

$(\"#datepicker\").datepicker( {viewMode: \"years\", minViewMode: \"years\"});

but inp

相关标签:
6条回答
  • 2021-01-30 21:25

    For bootstrap datetimepicker, assign decade value as follow:

    $(".years").datetimepicker({
        format: "yyyy",
        startView: 'decade',
        minView: 'decade',
        viewSelect: 'decade',
        autoclose: true,
    });
    
    0 讨论(0)
  • 2021-01-30 21:28

    For bootstrap 3 datepicker. (Note the capital letters)

    $("#datetimepicker").datetimepicker( {
      format: "YYYY",
      viewMode: "years"
    });
    
    0 讨论(0)
  • 2021-01-30 21:28
    format: "YYYY" 
    

    Should be capital instead of "yyyy"

    0 讨论(0)
  • 2021-01-30 21:29

    always year for bootstrap 3 datetimepicker https://eonasdan.github.io/bootstrap-datetimepicker/

       $('#year').datetimepicker({
            format: 'YYYY',
            viewMode: "years",
        });
    
        $("#year").on("dp.hide", function (e) {
            $('#year').datetimepicker('destroy');
            $('#year').datetimepicker({
                format: 'YYYY',
                viewMode: "years",
            });
        });
    
    0 讨论(0)
  • 2021-01-30 21:33

    Try this

    $("#datepicker").datepicker({
        format: "yyyy",
        viewMode: "years", 
        minViewMode: "years"
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" rel="stylesheet"/>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    
    
    <input type="text" id="datepicker" />

    $("#datepicker").datepicker( {
        format: " yyyy", // Notice the Extra space at the beginning
        viewMode: "years", 
        minViewMode: "years"
    });
    
    0 讨论(0)
  • 2021-01-30 21:40
    $("#year").datepicker( {
        format: "yyyy",
        viewMode: "years", 
        minViewMode: "years"
    }).on('changeDate', function(e){
        $(this).datepicker('hide');
    });
    
    0 讨论(0)
提交回复
热议问题