Why does IE (IE8, specifically) not highlight sele

2019-09-09 14:11发布

问题:

I am having a multi select box in a JSP page which has some options and is disabled.

<select id="mySelectBox" multiple disabled>
    <option value="first" selected>First</option>
    <option value="second">Second</option>
    <option value="third">Third</option>
    <option value="fourth" selected>Fourth</option>
</select>

I have the first and the fourth options selected, but they are not highlighted in IE They are properly highlighted when I use Firefox.

Is there any solution or workaround for this?

EDIT: My DOCTYPE is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> But even with that I don't see any difference.

回答1:

I hope i clearly understand what you want to do, but i can sugest to do it with little jquery?

<script type="text/javascript"> 
   $(document).ready(function() {
         $("#mySelectBox option:selected").css('background','black');
   });
</script>


回答2:

Interestingly, this CSS workaround seems to have fixed my issue!!

select[disabled="disabled"][multiple="multiple"]{
    background-color:#D4D0C8;
} 
select[disabled="disabled"][multiple="multiple"] option[selected="selected"]{
    background-color:navy;
}

Interesting because, earlier I had used the same to no effect. Perhaps I had missed out on something then.