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

質問編集履歴

3

2022/02/02 03:45

投稿

meron88
meron88

スコア50

title CHANGED
File without changes
body CHANGED
@@ -1,54 +1,55 @@
1
- ### 前提・実現したいこと
2
- 初歩的なことかもしれませんが、、
3
- 選択ボタンをクリックした際に、クリックした行の値を取得したいが、
4
- どの行をクリックしても、みかんとA1の値が取得されてしまいます。
5
-
6
- よろしくお願いいたします。
7
-
8
- ### 該当のソースコード
9
-
10
- ```html
11
- <table class="table table-hover table-bordered" id="table">
12
- <thead class="thead-light" style="position: sticky; top: 0; z-index: 1;">
13
- <tr>
14
- <th scope="col" class="text-center">選択</th>
15
- <th scope="col" class="text-center">商品名</th>
16
- <th scope="col" class="text-center">商品CDCD</th>
17
- </tr>
18
- </thead>
19
- <tbody>
20
- <tr id="somerow">
21
- <td class="text-center">
22
- <button class="btn btn-success ml-2" type="button" onclick="btnClick();">選択</button>
23
- </td>
24
- <td>みかん</td>
25
- <td>A1</td>
26
- </tr>
27
- <tr id="somerow">
28
- <td class="text-center">
29
- <button class="btn btn-success ml-2" type="button" onclick="btnClick();">選択</button>
30
- </td>
31
- <td>メロン</td>
32
- <td>B1</td>
33
- </tr>
34
- </tbody>
35
- </table>
36
- ```
37
-
38
- ```javascript
39
- <script type="application/javascript">
40
- function btnClick() {
41
- var Row = document.getElementById("somerow");
42
- var Cells = Row.getElementsByTagName("td");
43
- const name = Cells[1].innerText;
44
- const cd = Cells[2].innerText;
45
- }
46
- </script>
47
- ```
48
-
49
- ### 試したこと
50
- tdタグの中の値を取得したが、全て1列目の みかんA1しか取得されない
51
-
52
- ### 補足情報(FW/ツールのバージョンなど)
53
-
1
+ ### 前提・実現したいこと
2
+ 初歩的なことかもしれませんが、、
3
+ 選択ボタンをクリックした際に、クリックした行の値を取得したいが、
4
+ どの行をクリックしても、みかんとA1の値が取得されてしまいます。
5
+
6
+ よろしくお願いいたします。
7
+
8
+
9
+ ### 該当のソースコード
10
+
11
+ ```html
12
+ <table class="table table-hover table-bordered" id="table">
13
+ <thead class="thead-light" style="position: sticky; top: 0; z-index: 1;">
14
+ <tr>
15
+ <th scope="col" class="text-center">選択</th>
16
+ <th scope="col" class="text-center">商品</th>
17
+ <th scope="col" class="text-center">商品CDCD</th>
18
+ </tr>
19
+ </thead>
20
+ <tbody>
21
+ <tr id="somerow">
22
+ <td class="text-center">
23
+ <button class="btn btn-success ml-2" type="button" onclick="btnClick();">選択</button>
24
+ </td>
25
+ <td>みかん</td>
26
+ <td>A1</td>
27
+ </tr>
28
+ <tr id="somerow">
29
+ <td class="text-center">
30
+ <button class="btn btn-success ml-2" type="button" onclick="btnClick();">選択</button>
31
+ </td>
32
+ <td>メロン</td>
33
+ <td>B1</td>
34
+ </tr>
35
+ </tbody>
36
+ </table>
37
+ ```
38
+
39
+ ```javascript
40
+ <script type="application/javascript">
41
+ function btnClick() {
42
+ var Row = document.getElementById("somerow");
43
+ var Cells = Row.getElementsByTagName("td");
44
+ const name = Cells[1].innerText;
45
+ const cd = Cells[2].innerText;
46
+ }
47
+ </script>
48
+ ```
49
+
50
+ ### 試した
51
+ tdタグの中の値を取得したが、全て1列目の みかんとA1しか取得されない
52
+
53
+ ### 補足情報(FW/ツールのバージョンなど)
54
+
54
55
  ここにより詳細な情報を記載してください。

2

2021/12/03 18:14

投稿

meron88
meron88

スコア50

title CHANGED
File without changes
body CHANGED
@@ -5,8 +5,6 @@
5
5
 
6
6
  よろしくお願いいたします。
7
7
 
8
- ![イメージ説明](8f8b8ff4401e8a4e4a5e04977517ea1b.png)
9
-
10
8
  ### 該当のソースコード
11
9
 
12
10
  ```html

1

javascriptを修正したしました。

2021/12/03 18:14

投稿

meron88
meron88

スコア50

title CHANGED
File without changes
body CHANGED
@@ -36,6 +36,7 @@
36
36
  </tbody>
37
37
  </table>
38
38
  ```
39
+
39
40
  ```javascript
40
41
  <script type="application/javascript">
41
42
  function btnClick() {