I am using the following code:
ieLessThan8OptionDisable = function() {
if ($.browser.msie && parseFloat($.browser.version) < 8) {
$("select").find("[disabled]").addClass("disabledforie").removeAttr("disabled");
$("select").change(function(){
var selected = $(this).val();
var disabled = $(this).find("[value="+selected+"]").hasClass("disabledforie");
if (disabled) {
alert("This option is disabled.\nSelect will be set to the first option.");
$(this).find("option:first").attr("selected","selected");
}
});
}
}
Basically this code is for disabled option in a select drop down box. It works perfectly except there is a usability issue.
Anytime I click on the option which should be disabled in IE, an alert pops up, and after that th开发者_如何学Goe select box resets to the first position. All is fine. Now when I click on the select box to open the drop down, it just closes. Basically I have to click on it 2 times at which point it opens.
I have tried this in IE6 and IE7. Both have this issue.
Any pointers would be great!
Thanks
This sounds like a focus issue. The select box has focus when you select a new option, then you pop up an alert which steals focus away from the select element. IE should be closing the select box automatically when the alert gets called but alas they probably didn't test this edge case. So the two clicks do the following:
- Return focus to the select element
- Select an item in the list
Add a call to blur before you invoke the alert:
if (disabled) {
this.blur();// add in
alert("This option is disabled.\nSelect will be set to the first option.");
$(this).find("option:first").attr("selected","selected");
}
PS - I haven't actually tested this, I don't have IE available right now
精彩评论