问题描述
我正在使用以下代码:
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.
每次我单击应在IE中禁用的选项时,都会弹出警报,然后选择框将重置为第一个位置.一切皆好.现在,当我单击选择框以打开下拉菜单时,它就关闭了.基本上,我必须单击它两次,然后打开它.
Anytime I click on the option which should be disabled in IE, an alert pops up, and after that the 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.
我已经在IE6和IE7中进行了尝试.两者都有这个问题.
I have tried this in IE6 and IE7. Both have this issue.
任何指针都很棒!
谢谢
推荐答案
这听起来像是焦点问题.该选择框具有焦点,当你选择一个新的选项,则弹出该次抢断,从选择元素焦点离开警报.当调用警报时,IE应该会自动关闭选择框,但是可惜他们可能没有测试这种情况.因此,两次单击将执行以下操作:
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:
- 将焦点返回到选择元素
- 在列表中选择一个项目
添加调用以模糊处理,然后再调用警报:
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-我尚未进行实际测试,我现在没有IE可用
PS - I haven't actually tested this, I don't have IE available right now
这篇关于使用这个jQuery/JavaScript的奇怪的IE问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!