【问题标题】:Element on focus error on IE8IE8上焦点错误的元素
【发布时间】:2013-10-24 19:31:04
【问题描述】:

当我尝试在 Internet Explorer 7/8 上集中一些输入并选择框时,我遇到了同样的错误。

jQuery 代码是这样的:

$("#planner input, #planner select").on("focus",function() {
            panel = $(this).parents(".panel").first();
            if (!panel.hasClass("active")) {
                tab = panel.data("tab");
                $("#planner .tabs li[data-tab="+tab+"] a").trigger("click");
            }
        }); 

谁能帮帮我?

编辑:

我把整个代码贴在这里

<script>

    $(document).ready(function(){

        $("#planner .tabs a").click(function() {
            $(this).parents("#planner").find(".panel.active").removeClass("active");
            $(this).parents("#planner").find(".tabs li.active").removeClass("active");
            $(this).parent().addClass("active");
            tab = $(this).parents("#planner").find(".tabs li").index($(this).parent());
            panel = $(this).parents("#planner").find(".panel");
            $(panel[tab]).addClass("active");
        }); 

        $("#planner #quote").validate({
        ignore: "",         
        errorPlacement: function(error, element) {
        error.appendTo(element.closest(".item"));
        }           
        });

        $("#planner input, #planner select").on("focus" , function() {
            panel = $(this).parents(".panel").first();
            if (!panel.hasClass("active")) {
                tab = panel.data("tab");
                $("#planner .tabs li[data-tab="+tab+"] a").trigger("click");
            }
        });

});
</script>

【问题讨论】:

  • 对象不支持该属性或方法
  • 请使用var。如果你不使用它,你会定义很多糟糕的全局变量!
  • @user2915304 哪一行给出了这个错误?

标签: jquery internet-explorer-8 cross-browser internet-explorer-7


【解决方案1】:

用“活跃”代替“焦点”有用吗?

更新:

以下在 ie8 中对我有用,一定是您活动中的问题

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <title></title>
    <script language="javascript">

        $(document).ready(function () {
            $("#planner input, #planner select").on("focus", function () {
                alert('focus');
            });
        });

    </script>
</head>
<body>
    <div id="planner">
        <input type="text"/>
    </div>
</body>
</html>

【讨论】:

  • 以前试过,不行。
【解决方案2】:

问题是您的 jQuery 文件版本。使用 jQuery 最新版本文件。

【讨论】:

  • 听起来很奇怪,我使用的是 jQuery v1.10.2
猜你喜欢
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 2016-08-12
  • 1970-01-01
相关资源
最近更新 更多