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

回答編集履歴

2

chousei

2021/09/21 10:35

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -3,7 +3,7 @@
3
3
  <script>
4
4
  $(function(){
5
5
  $('#chk').on('click',function(){
6
- let forcusNum = $('input:radio[name="Genre"]').index($(':checked'));
6
+ var forcusNum = $('[name=Genre]').index($(':checked'));
7
7
  console.log(forcusNum);
8
8
  });
9
9
  });

1

chousei

2021/09/21 10:35

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -1,5 +1,21 @@
1
1
  indexの考え方が違います
2
2
  ```javascript
3
+ <script>
4
+ $(function(){
5
+ $('#chk').on('click',function(){
3
- let forcusNum = $('input:radio[name="Genre"]').index($(':checked'));
6
+ let forcusNum = $('input:radio[name="Genre"]').index($(':checked'));
4
- console.log(forcusNum);
7
+ console.log(forcusNum);
8
+ });
9
+ });
10
+ </script>
11
+ <form>
12
+ <label><input name="Genre" type="radio" value="aaa">A</label>
13
+ <label><input name="Genre" type="radio" value="bbb">B</label>
14
+ <label><input name="Genre" type="radio" value="ccc">C</label>
15
+ <label><input name="Genre" type="radio" value="ddd">D</label>
16
+ <label><input name="Genre" type="radio" value="eee">E</label><br>
17
+ <input type="button" id="chk" value="check">
18
+ <input type="reset" value="resett">
19
+ </form>
20
+
5
21
  ```