IE6中select标签的option不能disabled的解决方案

本文介绍了一个针对IE6浏览器不支持select元素中option禁用状态的问题解决方案。通过使用select-option-disabled-emulation.js脚本文件,可以实现在老旧浏览器上模拟禁用选项的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工作中需要用到disabled掉一些select的option,结果发现IE6没有实现它。
还好我们下载select-option-disabled-emulation.js文件即可自动完成disabled标记的工作。
代码如下:

  1. window.onload =  function () {  
  2.   if  (document.getElementsByTagName) {  
  3.     var  s = document.getElementsByTagName( "select" );  
  4.   
  5.     if  (s.length > 0) {  
  6.       window.select_current = new  Array();  
  7.   
  8.       for  ( var  i=0, select; select = s[i]; i++) {  
  9.         select.onfocus = function (){ window.select_current[ this .id] =  this .selectedIndex; }  
  10.         select.onchange = function (){ restore( this ); }  
  11.         emulate(select);  
  12.       }  
  13.     }  
  14.   }  
  15. }  
  16.   
  17. function  restore(e) {  
  18.   if  (e.options[e.selectedIndex].disabled) {  
  19.     e.selectedIndex = window.select_current[e.id];  
  20.   }  
  21. }  
  22.   
  23. function  emulate(e) {  
  24.   for  ( var  i=0, option; option = e.options[i]; i++) {  
  25.     if  (option.disabled) {  
  26.       option.style.color = "graytext" ;  
  27.     }  
  28.     else  {  
  29.       option.style.color = "menutext" ;  
  30.     }  
  31.   }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值