IE6 select的option的disabled属性没有效果及解决方案

今天遇到了这个问题 ,Mark下

解決ie6,ie7的select option disabled沒有作用的問題 Select, Option, Disabled And The JavaScript Solution In IE7, IE6, IE5.5

解決方案:
http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

下載js檔, 並include到頁面即可, 作法是把頁面的 select element找出來, 判斷有 disabled的option就變顏色且不可選擇
http://www.lattimore.id.au/files/examples/select-option-disabled-emulation.js

因為只有在ie7以下的版本有問題, 其他瀏覽器沒問題, 所以我改寫了一下



if (navigator.appVersion.indexOf("MSIE 5.5") >= 0 || navigator.appVersion.indexOf("MSIE 6.0") >= 0 || navigator.appVersion.indexOf("MSIE 7.0") >= 0)
{
window.onload = ReloadSelectElement;
}
function ReloadSelectElement() {


if (document.getElementsByTagName) {
var s = document.getElementsByTagName("select");

if (s.length > 0) {
window.select_current = new Array();

for (var i=0, select; select = s[i]; i++) {
select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
select.onchange = function(){ restore(this); }
emulate(select);
}
}
}
}

function restore(e) {
if (e.options[e.selectedIndex].disabled) {
e.selectedIndex = window.select_current[e.id];
}
}

function emulate(e) {
for (var i=0, option; option = e.options[i]; i++) {
if (option.disabled) {
option.style.color = "graytext";
}
else {
option.style.color = "menutext";
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值