2016-09-24 6 views
1

私は、ブートストラップ日付ピッカーを使用していますが、それは日、月、年はこれを試してくださいテキストボックスにのみ日付ピッカーでは、私はショーの年間たいテキストボックスを使用して年のみを表示する方法はありますか?

+3

可能な重複[jQueryのUI DatePickerの年だけを表示する](http://stackoverflow.com/questions/13528623/jquery-ui-datepicker-to-show-year-only) –

答えて

2

を示しています。

$("#datepicker").datepicker({ 
    format: " yyyy", //see there is extra space in format, dont remove it 
    viewMode: "years", 
    minViewMode: "years" 
}); 

使用この:

<html lang="en"> 

<head> 


    <title>Bootstrap - year picker only example</title> 

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 

    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet"> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script> 


</head> 

<body> 


<div class="container text-center"> 


    <h2>Bootstrap - year picker only example</h2> 

    <input class="date-own form-control" style="width: 300px;" type="text"> 


    <script type="text/javascript"> 

     $('.date-own').datepicker({ 

     minViewMode: 2, 

     format: 'yyyy' 

     }); 

    </script> 


</div> 


</body> 

</html> 
+0

私はすでに を試しました <入力クラス= "フォームコントロール日付ピッカー" ID = "yearofpub" NAME = "yearofpub" タイプ= "テキスト"> $( "#1 yearofpub")日付ピッカー ({ 形式: "YYYY"、 ビューモード: "年"、 minViewMode: "年" }); しかし、私はほんの1年しか欲しくない –

+0

更新された回答を確認してください。 –

+0

私のアプリケーションでdatepickerを複数回使用しましたこの同じbootstrap datepickerプラグイン、jqueryに特定のテキストボックスが1年しか表示されない場合 –

関連する問題