0

我正在用 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完成之前发生的更新?

谢谢你的帮助

埃德

4

1 回答 1

0

既然您正在超时并且它可以工作,那么可能是在文档准备好之后加载了表单元素吗?IE 加载了 ajax 还是用 javascript 创建的?

我知道 JQuery 角落尝试在每个浏览器中使用 CSS3,但如果它是 IE,它会生成一堆 div。难道是在 IE6/7 中它只需要更长的时间,所以不需要超时>

于 2010-11-03T20:48:51.000 回答