我正在用 ASP.NET MVC 开发一个 Web 应用程序。我最近使用 jQuery Rounded Corners 插件 ( http://plugins.jquery.com/project/corners )添加了圆角。这似乎让 IE8(但不是 6 或 7,或 Firefox)感到不安,因为我不能再在 $(document).ready() 中设置焦点。
这是问题的一个例子:
$(document).ready(function() {
// using jQuery rounded corners plugin
$("#centre").corners();
// this doesn't have any effect in IE8
$("#emailAddress").focus();
});
其中#centre 包含我们的登录页面,#emailAddress 是其中的第一个字段。
emailAddress 字段应该获得输入焦点。它在 IE6 & 7 和 Firefox 中有效,但在 IE8 中没有。如果您注释掉两条圆角线,那么它可以工作。
我也尝试将焦点线移动到 $(window).load():
$(window).load(function() {
$("#emailAddress").focus();
});
这也不起作用。但是,如果我使用超时设置焦点,那么它可以工作:
$(document).ready(function() {
// using jQuery rounded corners plugin
$("#centre").corners();
// this doesn't have any effect in IE8
setTimeout(function() { $("#emailAddress").focus(); }, 100);
});
我不确定为什么在超时后设置焦点应该有效。可能是因为圆角操作修改了DOM(他们在容器的顶部和底部添加了一系列DIV来创建圆角边框),这需要一些时间,并且focus()是在DOM完成之前发生的更新?
谢谢你的帮助
埃德