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

工作中需要用到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.   }  

你可能感兴趣的:(ajax实现动态网站技术,ie,function,工作)