回答編集履歴

5

補足説明

2019/03/12 06:27

投稿

FKM
FKM

スコア3640

test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
 
39
- テス結果
39
+ 最終的にこのようにして解決させました。イベンは複製先は継承されないが、複製元は維持されるという特性を利用しています。
40
40
 
41
41
 
42
42
 

4

アイコンは任意

2019/03/12 06:27

投稿

FKM
FKM

スコア3640

test CHANGED
@@ -42,7 +42,25 @@
42
42
 
43
43
  ```
44
44
 
45
+ //カレンダーの設定
46
+
47
+   var status = {
48
+
49
+   buttonImage: "(画像URL)", // カレンダーアイコン画像
50
+
51
+   buttonText: "カレンダーから選択", // ツールチップ表示文言
52
+
53
+   buttonImageOnly: true, // 画像として表示
54
+
55
+   showOn: "both", // カレンダー呼び出し元の定義
56
+
57
+   dateFormat:'yy-mm-dd',
58
+
59
+   };
60
+
61
+ //カレンダーイベント
62
+
45
- $('.test_date').datepicker();
63
+   $('.test_date').datepicker(status);
46
64
 
47
65
  $(document).on('click', '[type="button"]', function(){
48
66
 
@@ -52,33 +70,23 @@
52
70
 
53
71
  $(r).after(clone);
54
72
 
73
+ //clearDatePickerSelector(status);
74
+
55
75
  $('.test_date', clone).removeClass("hasDatepicker")
56
76
 
57
77
  .removeData("datepicker")
58
78
 
59
79
  .removeAttr("id")
60
80
 
61
- .datepicker();
81
+ .datepicker(status)
82
+
83
+ .parent().find('img').not(':first').remove();
62
84
 
63
85
  });
64
86
 
65
- function setDatePickerSelector($selector){
87
+ })
66
88
 
67
- $selector.each(function(){
68
89
 
69
- $o = $(this);
70
-
71
- $o.datepicker({ buttonText:'カレンダー表示',dateFormat:'yy-mm-dd' });
72
-
73
- $o.datepicker("option", "showOn", 'button');
74
-
75
- $o.datepicker("option", "buttonImageOnly", true);
76
-
77
- $o.datepicker("option", "buttonImage", 'images/calendar.png');
78
-
79
- });
80
-
81
- }
82
90
 
83
91
 
84
92
 

3

これでいけます

2019/03/12 06:16

投稿

FKM
FKM

スコア3640

test CHANGED
@@ -33,3 +33,53 @@
33
33
  }
34
34
 
35
35
  ```
36
+
37
+
38
+
39
+ テスト結果
40
+
41
+
42
+
43
+ ```
44
+
45
+ $('.test_date').datepicker();
46
+
47
+ $(document).on('click', '[type="button"]', function(){
48
+
49
+ var r = this.parentNode;
50
+
51
+ var clone = $(r).clone();
52
+
53
+ $(r).after(clone);
54
+
55
+ $('.test_date', clone).removeClass("hasDatepicker")
56
+
57
+ .removeData("datepicker")
58
+
59
+ .removeAttr("id")
60
+
61
+ .datepicker();
62
+
63
+ });
64
+
65
+ function setDatePickerSelector($selector){
66
+
67
+ $selector.each(function(){
68
+
69
+ $o = $(this);
70
+
71
+ $o.datepicker({ buttonText:'カレンダー表示',dateFormat:'yy-mm-dd' });
72
+
73
+ $o.datepicker("option", "showOn", 'button');
74
+
75
+ $o.datepicker("option", "buttonImageOnly", true);
76
+
77
+ $o.datepicker("option", "buttonImage", 'images/calendar.png');
78
+
79
+ });
80
+
81
+ }
82
+
83
+
84
+
85
+ ```

2

eachはいらないかも

2019/03/11 12:40

投稿

FKM
FKM

スコア3640

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- また、至る箇所にカレンダーAPIを使用するなら、ユニークにしか制御できないidではなくてクラスで指定して、その中でjQueryのeachメソッドを利用したらいいと思います。
11
+ また、至る箇所にカレンダーAPIを使用するなら、ユニークにしか制御できないidではなくてクラスで指定して、その中でjQueryのメソッドを利用したらいいと思います。
12
12
 
13
13
 
14
14
 
@@ -16,23 +16,19 @@
16
16
 
17
17
  function setDatePickerSelector($selector){
18
18
 
19
- $selector.each(function(){
19
+ $(document).on("click",$selector,function(){
20
20
 
21
- $(this).on("click",function(){
21
+ $o = $(this);
22
22
 
23
- $o = $(this);
23
+ $o.datepicker({ buttonText:'カレンダー表示',dateFormat:'yy-mm-dd' });
24
24
 
25
- $o.datepicker({ buttonText:'カレンダー表示',dateFormat:'yy-mm-dd' });
25
+ $o.datepicker("option", "showOn", 'button');
26
26
 
27
- $o.datepicker("option", "showOn", 'button');
27
+ $o.datepicker("option", "buttonImageOnly", true);
28
28
 
29
- $o.datepicker("option", "buttonImageOnly", true);
29
+ $o.datepicker("option", "buttonImage", 'images/calendar.png');
30
30
 
31
- $o.datepicker("option", "buttonImage", 'images/calendar.png');
32
-
33
- })
31
+ })
34
-
35
- });
36
32
 
37
33
  }
38
34
 

1

このようにする

2019/03/11 01:20

投稿

FKM
FKM

スコア3640

test CHANGED
@@ -9,3 +9,31 @@
9
9
 
10
10
 
11
11
  また、至る箇所にカレンダーAPIを使用するなら、ユニークにしか制御できないidではなくてクラスで指定して、その中でjQueryのeachメソッドを利用したらいいと思います。
12
+
13
+
14
+
15
+ ```
16
+
17
+ function setDatePickerSelector($selector){
18
+
19
+ $selector.each(function(){
20
+
21
+ $(this).on("click",function(){
22
+
23
+ $o = $(this);
24
+
25
+ $o.datepicker({ buttonText:'カレンダー表示',dateFormat:'yy-mm-dd' });
26
+
27
+ $o.datepicker("option", "showOn", 'button');
28
+
29
+ $o.datepicker("option", "buttonImageOnly", true);
30
+
31
+ $o.datepicker("option", "buttonImage", 'images/calendar.png');
32
+
33
+ })
34
+
35
+ });
36
+
37
+ }
38
+
39
+ ```