質問するログイン新規登録

回答編集履歴

1

前提条件が変わったため追記。

2016/04/06 16:20

投稿

kei344
kei344

スコア69643

answer CHANGED
@@ -13,4 +13,30 @@
13
13
  [http://eonasdan.github.io/bootstrap-datetimepicker/Events/](http://eonasdan.github.io/bootstrap-datetimepicker/Events/)
14
14
 
15
15
  【javascript - bootstrap 3 datetimepicker((eonasdan)) - e.date is undefined on "dp.show" - Stack Overflow】
16
- [http://stackoverflow.com/questions/31034675/bootstrap-3-datetimepickereonasdan-e-date-is-undefined-on-dp-show](http://stackoverflow.com/questions/31034675/bootstrap-3-datetimepickereonasdan-e-date-is-undefined-on-dp-show)
16
+ [http://stackoverflow.com/questions/31034675/bootstrap-3-datetimepickereonasdan-e-date-is-undefined-on-dp-show](http://stackoverflow.com/questions/31034675/bootstrap-3-datetimepickereonasdan-e-date-is-undefined-on-dp-show)
17
+
18
+ ---
19
+
20
+ **ここから追記:**
21
+
22
+ ---
23
+
24
+ こっちだったようなので、修正。
25
+
26
+ 【Events — bootstrap-datepicker documentation】
27
+ http://bootstrap-datepicker.readthedocs.org/en/stable/events.html#changedate
28
+
29
+ dp.change → changeDate に変えて、イベントの返り値がDateオブジェクトに変わる感じかな。
30
+ ```JavaScript
31
+ $( '#dp_pos1' ).datepicker().on( 'changeDate', function( e ) {
32
+ console.log( e.date ); // ここでDateオブジェクトの取得がきちんとできているか確認
33
+ $( '#target_year' ).val( e.date.getFullYear() );
34
+ $( '#target_month' ).val( e.date.getMonth() + 1 );
35
+ $( '#target_day' ).val( e.date.getDate() );
36
+ });
37
+ ```
38
+
39
+ コンソールに出力されるのに、値の入手に失敗する場合は、``$( '#dp_pos1' ).val()`` を採ってうまく使ってください。きちんと動くといいなぁ。
40
+
41
+
42
+