select の option 項目を追加する javascript を組んでいるのですが
IE だけ項目追加ができません。Windows の Firefox2、Safari は期待
通りに項目が追加できました。
option.value を指定しないと IE でも追加できます。IE 専用に特別な
別プログラムが必要なのでしょうか。ご存知の方よろしくお願いします。
var selectBox = document.getElementById("select1");
var option = document.createElement('option');
option.setAttribute('value','my_value');
option.appendChild(document.createTextNode('my_text'));
selectBox.appendChild(option);
3行目をコメントアウトすれば IE でも select にデータが追加され
ますが、肝心の value がないのでプログラム的にダメなんです。
No.1ベストアンサー
- 回答日時:
う~ん・・・Win版IE6では普通に動いてますがどのIEについて言っている
のでしょ?
<script>
window.onload=function(){
var selectBox = document.getElementById("select1");
var option = document.createElement('option');
option.setAttribute('value','my_value');
option.appendChild(document.createTextNode('my_text'));
selectBox.appendChild(option);
}
</script>
<select id="select1" onchange="alert(this.value)">
<option value="">選択する</option>
</select>
回答ありがとうございます。
IEはWin版の6と7です。Macは手元にないのでわかりません。
教えていただいたコードのみでは・・・動きます。なんででしょう。
ただ、これでこの書き方自体は間違いでないことがわかりましたので
視点を変えて調査します。ありがとうございました。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
全てのselect要素をデフォルト...
-
スマホのフォームでのselect複...
-
javascript:データを日本語で...
-
JavaScriptで<select>の<option...
-
VBScriptでHTMLのセレクトボッ...
-
セレクトボックスを未選択の状...
-
<input>の選択肢をプルダウンメ...
-
プルダウンで選択した項目にあ...
-
プルダウンを選択していないと...
-
2つのセレクトボックスで選ば...
-
return trueとreturn falseの用...
-
特定<table>内の<td>の色を変える
-
value内に変数を入れたい
-
確認ダイアログの出し方(JavaS...
-
至急!GetElementById でtdの...
-
HTML中のTABLEのデータを抽出す...
-
ひ孫に当たるiframe から親ウイ...
-
XMLHttpRequestを利用してPHPへ...
-
innerHTML内では改行は禁止?
-
プルダウンで選択すると、DBの...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
プルダウン選択を変更すると、...
-
<input>の選択肢をプルダウンメ...
-
Selectボックスの一覧表示方法
-
javascriptでセレクトボックス...
-
同じ名前のセレクトがある場合...
-
全てのselect要素をデフォルト...
-
【javascript】連想配列からセ...
-
スマホのフォームでのselect複...
-
selectを変更不可にしたい
-
JavaScriptで<select>の<option...
-
複数のプルダウンを1つにまとめ...
-
プルダウンの値によって活性・...
-
VBScriptでHTMLのセレクトボッ...
-
webページの一部のみの更新につ...
-
selectのすべての値を送信する方法
-
javascript:データを日本語で...
-
プルダウンのoptionの表示・非...
-
リストボックス内の重複したも...
-
select要素のvalueを配列で取得...
-
C#(csファイル)とjavascriptと...
おすすめ情報