close

本文說明 datepicker 事件 onChangeMonthYear

當日曆移動到新的月份或年份時,觸法此事件

一、基本JS/HTML語法

JS:

    $("#datepicker").datepicker({

      onChangeMonthYear : fun1

    });

二、基本說明

onChangeMonthYear : fun1

default : null 不多做動作

當日曆移動到新的月份或年份時,叫用此方法。

function(Integer year,Integer month,Object inst)

fun1:當日曆移動到新的月份或年份時,叫用此方法,顯示訊息。

function fun1(year, month, inst) {

  $("#showDateBox").append("onChangeMonthYear......"+year+"/"+month);

  console.log("year", year);

  console.log("month", month);

  console.log("inst", inst);

}

三、程式內容

<html>
<head>
<title>jquery.datepicker 26</title>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
  $(function() {
    //26-jQuery datepicker 事件 onChangeMonthYear
    $("#datepicker").datepicker({
      //設定日期格式
      dateFormat : "yy/mm/dd",
      //當日曆移動到新的月份或年份時,叫用此方法
      //default 不多做動作
      onChangeMonthYear : fun1
    });
    //function(Integer year,Integer month,Object inst)
    //當日曆移動到新的月份或年份時,叫用此方法
    function fun1(year, month, inst) {
   $("#showDateBox").append("onChangeMonthYear......"+year+"/"+month);
      console.log("year", year);
      console.log("month", month);
      console.log("inst", inst);
    }
  });
</script>
</head>
<body>
  <div class="datetest">
    <p class="datag">
      Date: <input type="text" id="datepicker" value="">
    </p>
  </div>
  <div>說明:jQuery datepicker 事件 onChangeMonthYear </div>
  <br>
  <div id="showDateBox"></div>
</body>
</html>
	

四、執行

圖1

五、測試

Date: 

說明:jQuery datepicker 事件 onChangeMonthYear

相關參考:

其它參考:

jQuery教學目錄

其它文章



arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()