IE吃我的'焦点'事件 [英] IE Eats my 'focus' event
问题描述
我有一个必须在IE 7/8(compat)中运行的应用程序。 (我知道,对吧?)
该应用程序包含以下功能....
如果我点击在下拉列表中,列表会检查其他地方的某些值,并根据查找到的匹配数量启用或禁用某些选项。我使用下拉列表的焦点事件来做到这一点。
如果我在真正的浏览器中运行此代码,它可以正常工作。如果我在启用兼容模式的IE7或8中运行它,我必须点击DDL两次;第一次激发我的焦点事件代码,第二次激发我的焦点事件代码,第二次激发我的焦点事件代码。
标记:
<!DOCTYPE html>
< html>
< head>
< / head>
< body>
< select id =aa>
< option> A< / option>
< option> B< / option>
< option> C< / option>
< option> D< / option>
< option> E< / option>
< option> F< / option>
< option> G< / option>
< / select>
< script src =script.js>< / script>
< / body>
< / html>
JS:
($#$)$(#aa)。 ;
kids.removeAttr(disabled);
kids.removeAttr(title);
if(countSelectedEvents == 0){
kids.slice (1).attr(disabled,disabled);
kids.slice(1).attr(title,此选项仅在选择一个或多个事件时可用);
kids.slice(4).attr(title,此选项仅在选择完全一个事件时才可用);
} else if(countSelectedEvents> 1){
kids。 (4).attr(disabled,disabled);
kids.slice(4).attr(title,这个选项只有在选择了一个事件时才可用);
}
返回true;
});
为方便起见,您可以在 plnkr 。如果有人知道如何让DDL在第一次点击时放开,我很乐意听到它。
更新:
这个问题在这里StackOverflow建议触发'focusout'事件,但这也不起作用。
更新II
看起来这是一个更通用的IE错误。它不能在IE11的原生mod中工作! : - (
您的额外开头括号 {
.focus()
函数事件。这可能会破坏您的代码。
而不是。 focus(function(){{})
,应该是 .focus(function(){})
(换句话说,在你的JS例子中删除第2行,并且应该设置)
I have an app that must run in IE 7/8(compat). (I know, right?)
The app includes the following functionality....
If I click on a dropdown list, the list checks some values elsewhere and, depending on the number of matches it finds it enables or disables some of the options. I make this happen using the focus event of the dropdown list.
If I run this code in a real browser, it works fine. If I run it in IE7 or 8 with compatibility mode enabled, I have to click the DDL twice; the first time fires my focus event code and the 2nd to get it to drop down.
The markup:
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<select id="aa">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
<option>F</option>
<option>G</option>
</select>
<script src="script.js"></script>
</body>
</html>
The JS:
$("#aa").focus(function() {
var countSelectedEvents = 2;
var kids = $("#aa").children("option");
kids.removeAttr("disabled");
kids.removeAttr("title");
if (countSelectedEvents == 0) {
kids.slice(1).attr("disabled", "disabled");
kids.slice(1).attr("title", "This option is only available if one or more Events are selected");
kids.slice(4).attr("title", "This option is only available if exactly ONE Event is selected");
} else if (countSelectedEvents > 1) {
kids.slice(4).attr("disabled", "disabled");
kids.slice(4).attr("title", "This option is only available if exactly ONE Event is selected");
}
return true;
});
For convenience, you can find this code on plnkr. If anyone knows how I can get the DDL to drop open on the first click, I'd love to hear about it.
UPDATE: This question here on StackOverflow suggests triggering the 'focusout' event, but that doesn't work either.
UPDATE II It seems that this is a more generic IE error. It doesn't work in native mod in IE11 either! :-(
You have an extra opening bracket {
in your .focus()
function event. That's probably breaking your code.
Instead of .focus(function(){{})
, should be .focus(function(){})
(in other words, remove line 2 in your JS example and should be set)
这篇关于IE吃我的'焦点'事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!