HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>首页 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="http://lyear.itshubao.com/css/bootstrap.min.css" rel="stylesheet">
<link href="http://example.itshubao.com/demo/css/materialdesignicons.min.css" rel="stylesheet">
<!--日期选择插件-->
<link rel="stylesheet" href="http://lyear.itshubao.com/js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
<link href="http://lyear.itshubao.com/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header"><h4>关于年和月的单独选择</h4></div>
        <div class="card-body">
          
          <p class="m-t-15">单独选择年份</p>
          <p class="text-danger">因为和通用初始化有些不一样,这里单独对此做初始化。</p>
          <input class="form-control m-b-10" type="text" id="example-datepicker-year" name="example-datepicker-year" data-date-format="yyyy" placeholder="yyyy">
          
          <p class="m-t-15">单独选择月份</p>
          <input class="form-control m-b-10" type="text" id="example-datepicker-month" name="example-datepicker-month" data-date-format="mm" placeholder="mm">
          
          <p class="m-t-15">单独选择天就不演示了,<code>data-date-format="dd"</code>即可。</p>
          
        </div>
      </div>
    </div>
    
  </div>
  
</div>


<script type="text/javascript" src="http://lyear.itshubao.com/js/jquery.min.js"></script>
<!--日期选择插件-->
<script src="http://lyear.itshubao.com/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="http://lyear.itshubao.com/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
</body>
</html>
CSS

  
JavaScript
    // 单独选择年份
	jQuery('#example-datepicker-year').each(function() {
	    var $input = jQuery(this);
		$input.datepicker({
            startView: 'decade',  
            endView: 'decade',
            maxViewMode: 'decade',  
            minViewMode: 'decade', 
			weekStart: 1,
			autoclose: true,
			todayHighlight: true,
			language: 'zh-CN',
		});
	});
    // 单独选择月份
	jQuery('#example-datepicker-month').each(function() {
	    var $input = jQuery(this);
		$input.datepicker({
            startView: 'month',  
            endView: 'month',
            maxViewMode: 'year',  
            minViewMode: 'year', 
			weekStart: 1,
			autoclose: true,
			todayHighlight: true,
			language: 'zh-CN',
		});
	});