回答編集履歴

1

回答内容の追加

2019/07/04 10:19

投稿

mar-kn
mar-kn

スコア306

test CHANGED
@@ -11,3 +11,41 @@
11
11
  });
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ ---
18
+
19
+ 2019-07-04 19:18 追記
20
+
21
+ 修正後も動かないのは、$.html() で追加した要素に対して、イベントのセットが効いていないものと思います。
22
+
23
+ 下記のように、要素を追加した後でイベントをセットしたら動くようにならないでしょうか?
24
+
25
+ ( $(input).prop('form_agree', 'agree') の部分でエラーが出るとは思います。)
26
+
27
+
28
+
29
+ ```javascript
30
+
31
+ /* .confirm__agree書き換え*/
32
+
33
+ $(function () {
34
+
35
+ $('.confirm__agree').html('<label class="checkbox"><input type="checkbox" name="form_agree" value="agree"></label><label class="checkbox_text"><a href="/mobile/xxxxxx-xxxxxx/" target="_blank" style="color: blue; text-decoration: underline;">規約</a>に同意します</label>');
36
+
37
+
38
+
39
+ /* label.checkboxが押されたら checkboxをtureにする */
40
+
41
+ $('label.checkbox').on('click', function () {
42
+
43
+ $(input).prop('form_agree', 'agree')
44
+
45
+ });
46
+
47
+ //↑ ブロックの内側に入れて、順番に処理が走るようにする
48
+
49
+ });
50
+
51
+ ```