作者tomin (for pete's sake)
看板Ajax
標題[討論] removeAttr, selected, IE bug?
時間Sat May 23 16:07:15 2009
IE似乎沒辦法消滅selected (以及disabled)
也就是在IE環境下 無法讓以下的黃色字消失
<option value="1" class="option_1"
selected="selected">1</option>
而且selected的值似乎只能是selected或true 沒有none, no這類的選項
我只是來討論我的發現 不期待有什麼解法 我寫的code如下
//both work fine except IE
//1.DOM solution, but IE doesn't act well
//getElementsByClassName("option_1").removeAttribute("selected");
//2.jquery, but not cross IE browser
$(".option_1").removeAttr("selected");
網路上有許多類似的問題,例如:
http://gimp4you.eu.org/sandbox/js/test/removeAttr.html
http://bbs.jquery.org.cn/read.php?tid-830-fpage-86.html
http://www.mail-archive.com/[email protected]/msg04018.html
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.40.183
※ 編輯: tomin 來自: 122.116.40.183 (05/23 16:12)
1F:→ TonyQ:想要移除selected的目的是? 05/23 16:19
我原本要達到的目標是排優先順序
比如說有三個select
1 2 3 飛機
1
2 3 火車
1 2
3 公車
1,2,3不能重覆
移除selected 我是用來移除重覆的選項
比如火車選1後 飛機又再選1 要將火車的1移除
※ 編輯: tomin 來自: 122.116.40.183 (05/23 18:17)
2F:→ TonyQ:唔 , 是真的要把 option remove 掉 , 還是改 selectIndex ? 05/23 18:22
3F:→ TonyQ:你說的需求感覺不需要特地繞遠路去移除 selected 欸 o_oa 05/23 18:22
4F:→ tomin:只要改selectIndex option可以remove 是attr才remove不掉 05/23 18:27