質問編集履歴
1
コードを見やすくした
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,42 +1,38 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
松 竹 梅というボタンを作ってそれを一度だけ押せる
|
3
|
-
|
4
|
-
|
3
|
+
HTML
|
5
|
-
<
|
4
|
+
<div>
|
5
|
+
<input type="button" value="松" onclick="btnClick(0);" >
|
6
|
+
<input type="button" value="竹" onclick="btnClick(1);>
|
7
|
+
<input type="button" value="梅" onclick="btnClick(2);>
|
8
|
+
<h2 id="msg"></h2>
|
9
|
+
</div>
|
10
|
+
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
11
|
+
表示例
|
12
|
+
|
13
|
+

|
14
|
+
|
15
|
+
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
16
|
+
Javascript
|
17
|
+
|
6
|
-
function btnClick(prm) {
|
18
|
+
function btnClick(prm) {
|
7
19
|
var text = ['松','竹','梅'];
|
8
20
|
var target = document.getElementsByClassName('select')
|
21
|
+
|
9
|
-
|
22
|
+
for (var i = 0; i < target.length; i++) {
|
23
|
+
|
10
|
-
|
24
|
+
target[i].removeAttribute('disabled');
|
25
|
+
|
11
|
-
|
26
|
+
}
|
12
|
-
target[prm].setAttribute('disabled', 'disabled');
|
27
|
+
target[prm].setAttribute('disabled', 'disabled');
|
13
|
-
document.getElementById("msg").textContent = text[prm];
|
28
|
+
document.getElementById("msg").textContent = text[prm];
|
14
|
-
}
|
29
|
+
}
|
15
|
-
|
30
|
+
|
16
|
-
|
31
|
+
|
32
|
+
|
17
33
|
|
18
|
-
|
34
|
+
|
19
|
-
|
35
|
+
|
20
|
-
<input type="button" value="竹" onclick="btnClick(1);">
|
21
|
-
<input type="button" value="梅" onclick="btnClick(2);">
|
22
|
-
<h2 id="msg"></h2>
|
23
|
-
</div>
|
24
|
-
というプログラムを書いたのですが
|
25
|
-
ボタンを押してもなにも表示されません
|
26
|
-
どこが間違ってるか教えていた咲ければ幸いです
|
27
|
-
|
28
|
-
### 発生している問題・エラーメッセージ
|
29
|
-
10イベント.html:60 Uncaught TypeError: Cannot read property 'setAttribute' of undefined
|
30
|
-
何を試しても上記のエラーメッセージが出てきます
|
31
|
-
```
|
32
|
-
エラーメッセージ
|
33
|
-
```10イベント.html:60 Uncaught TypeError: Cannot read property 'setAttribute' of undefined
|
34
|
-
|
35
|
-
### 該当のソースコード
|
36
|
-
target[prm].setAttribute('disabled', 'disabled');
|
37
|
-
|
38
|
-
|
39
|
-
|
40
36
|
### 試したこと
|
41
37
|
|
42
38
|
target[prm].setAttribute('disabled', 'disabled');これを消すと何回でも押せるボタンができたので引数が間違ってるのかと思いi,textなどを入れてみました
|