Simulando options disabled no IE - solução
Fonte: Simulando options disabled no IE
Bora lá sem muito papo:
Se você colocar um atributo "disabled" em um option ele deverá ficar desabilitado, ou seja, indisponível. Exemplo:
<select> <option>opt 1</option> <option disabled='disabled'>opt 2</option> <option>opt 3</option></select>Isto acontece bem nos navegadores padrão.
No nosso velho amigo IE não acontece. Teste e veja.
O que fazer? Bom, vamos então 'simular' que o option está desabilitado via javascript.
Está abaixo:
<!--[if lte IE 6]><script>function ativaOptionsDisabled(){ var sels = document.getElementsByTagName('select'); for(var i=0; i < sels.length; i++){ sels[i].onchange= function(){ //pra se mudar pro desabilitado if(this.options[this.selectedIndex].disabled){ if(this.options.length<=1){ this.selectedIndex = -1; }else if(this.selectedIndex < this.options.length - 1){ this.selectedIndex++; }else{ this.selectedIndex--; } } } if(sels[i].options[sels[i].selectedIndex].disabled){ //se o selecionado atual é desabilitado chamo o onchange sels[i].onchange(); } for(var j=0; j < sels[i].options.length; j++){ //colocando o estilo if(sels[i].options[j].disabled){ sels[i].options[j].style.color = '#CCC'; } } }}window.attachEvent("onload", ativaOptionsDisabled)</script><![endif]-->
Pronto.
//Obs. Esta função substitui algum outro evento ONCHANGE que tenha sido colocado antes pra algum option.
Discussão (2)
Carregando comentários...