回答編集履歴

1

仕様変更対応分追記

2019/10/25 07:47

投稿

x_x
x_x

スコア13749

test CHANGED
@@ -15,3 +15,43 @@
15
15
  [https://api.jquery.com/attribute-ends-with-selector/](https://api.jquery.com/attribute-ends-with-selector/)
16
16
 
17
17
  [https://api.jquery.com/prop/](https://api.jquery.com/prop/)
18
+
19
+
20
+
21
+ -- 仕様変更対応分追記
22
+
23
+
24
+
25
+ ```jQuery
26
+
27
+ $(document).on('change', '[type="checkbox"][name$="\]"]', function(event) {
28
+
29
+ var target = event.target;
30
+
31
+ if (!target.checked) {
32
+
33
+ return true;
34
+
35
+ }
36
+
37
+
38
+
39
+ var escapedName = CSS.escape(target.name.replace(/.+[/, '['));
40
+
41
+ if (target.name.startsWith('hogehoge')) {
42
+
43
+ $('[name$="' + escapedName + '"]').not(target).prop('checked', false);
44
+
45
+ } else {
46
+
47
+ $('[name="hogehoge' + escapedName + '"]').prop('checked', false);
48
+
49
+ }
50
+
51
+ });
52
+
53
+ ```
54
+
55
+ [https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape](https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape)
56
+
57
+ [https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)