作者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