As IE 7 does not support the disabled
attribute, I am using jQuery to add an event handler to the change
event which checks if there is a disabled
attribute on the select and setting the css color
to grey
on the disabled option.
However, as soon I click on the dropdown its closes my dropdown first then re-draw the new one with the grey color.
Here is my code:
(function($) {
$('select').change(function() {
if (this.options[this.selectedIndex].disabled) {
if (this.options.length == 0) {
this.selectedIndex = -1;
} else {
this.selectedIndex--;
}
//$(this).trigger('change');
}
});
$('select').each(function(it) {
if (this.options[this.selectedIndex].disabled) {
this.onchange();
}
});
$('select').click(function(e) {
//e.stopPropagation();
开发者_运维问答$(this).find('option[disabled]').css({
'color': '#cccccc'
});
});
})(jQuery);
Check out this example I've made for you: http://jsfiddle.net/auNVE/
It should give you enough information for further development!
Good luck!
Edit
Update after having more information
http://jsfiddle.net/auNVE/1/
Edit
Now with mousedown
instead of click
http://jsfiddle.net/auNVE/2/
精彩评论