回答編集履歴

6

訂正

2018/11/26 06:33

投稿

退会済みユーザー
test CHANGED
@@ -1,31 +1,29 @@
1
1
  ```javascript
2
2
 
3
- function test() {
3
+ window.onload = () => {
4
4
 
5
- var key = document.getElementById("test_id").getAttribute("value");
5
+ document.getElementById('test_id').addEventListener('blur', (e) => {
6
6
 
7
- var a = ""
7
+ let obj = e.target
8
8
 
9
- for(var opt of document.getElementById("test_list").children){
9
+ let key = obj.value;
10
10
 
11
- if(opt.getAttribute("value")==key){
11
+ let a = null;
12
12
 
13
- a = opt.getAttribute("label")
13
+ Array.from(document.getElementById('test_list').children).forEach((opt) => {
14
14
 
15
- bleak;
15
+ if(opt.value == key){
16
16
 
17
- }
17
+ a = opt.label;
18
18
 
19
- }
19
+ }
20
20
 
21
- console.log(a);
21
+ });
22
22
 
23
+ console.log(a);
24
+
25
+ });
26
+
23
- }
27
+ }
24
28
 
25
29
  ```
26
-
27
-
28
-
29
- ##### 参考リンク
30
-
31
- [element.getAttribute](https://developer.mozilla.org/ja/docs/Web/API/Element/getAttribute)

5

誤字の修正

2018/11/26 06:33

投稿

退会済みユーザー
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  var a = ""
8
8
 
9
- for(opt of document.getElementById("test_list").children){
9
+ for(var opt of document.getElementById("test_list").children){
10
10
 
11
11
  if(opt.getAttribute("value")==key){
12
12
 

4

打ち間違いを訂正

2018/11/26 04:12

投稿

退会済みユーザー
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  var a = ""
8
8
 
9
- for(opt in document.getElementById("test_list").children){
9
+ for(opt of document.getElementById("test_list").children){
10
10
 
11
11
  if(opt.getAttribute("value")==key){
12
12
 

3

内容不足を訂正

2018/11/26 04:11

投稿

退会済みユーザー
test CHANGED
@@ -2,7 +2,21 @@
2
2
 
3
3
  function test() {
4
4
 
5
- var a = document.getElementById("test_id").getAttribute("value");
5
+ var key = document.getElementById("test_id").getAttribute("value");
6
+
7
+ var a = ""
8
+
9
+ for(opt in document.getElementById("test_list").children){
10
+
11
+ if(opt.getAttribute("value")==key){
12
+
13
+ a = opt.getAttribute("label")
14
+
15
+ bleak;
16
+
17
+ }
18
+
19
+ }
6
20
 
7
21
  console.log(a);
8
22
 

2

誤字の修正

2018/11/26 04:10

投稿

退会済みユーザー
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  function test() {
4
4
 
5
- var a = document.getElementById("test_id").getAttribute("label");
5
+ var a = document.getElementById("test_id").getAttribute("value");
6
6
 
7
7
  console.log(a);
8
8
 

1

参考リンク追加

2018/11/26 04:02

投稿

退会済みユーザー
test CHANGED
@@ -9,3 +9,9 @@
9
9
  }
10
10
 
11
11
  ```
12
+
13
+
14
+
15
+ ##### 参考リンク
16
+
17
+ [element.getAttribute](https://developer.mozilla.org/ja/docs/Web/API/Element/getAttribute)