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

回答編集履歴

2

Option(text,value)の形に変更

2017/09/25 11:42

投稿

namnium1125
namnium1125

スコア2045

answer CHANGED
@@ -20,9 +20,7 @@
20
20
  histories.push(unescape(str.substring(8).replace(";","")));
21
21
  });
22
22
  histories.forEach(function(his){
23
- var op = document.createElement("option");
24
- op.value = his;
25
- op.innerHTML = his;
23
+ var op = new Option(his,his);
26
24
  select.appendChild(op);
27
25
  });
28
26
  }
@@ -30,9 +28,7 @@
30
28
  button.addEventListener("click",function(){
31
29
  if(text.value!=""){
32
30
  document.cookie = "cookie"+histories.length+"="+escape(text.value)+"; max-age=604800";
33
- var op = document.createElement("option");
31
+ var op = new Option(text.value,text.value);
34
- op.value = text.value;
35
- op.innerHTML = text.value;
36
32
  select.appendChild(op);
37
33
  }
38
34
  },false);

1

コードの改良

2017/09/25 11:42

投稿

namnium1125
namnium1125

スコア2045

answer CHANGED
@@ -30,6 +30,10 @@
30
30
  button.addEventListener("click",function(){
31
31
  if(text.value!=""){
32
32
  document.cookie = "cookie"+histories.length+"="+escape(text.value)+"; max-age=604800";
33
+ var op = document.createElement("option");
34
+ op.value = text.value;
35
+ op.innerHTML = text.value;
36
+ select.appendChild(op);
33
37
  }
34
38
  },false);
35
39