Javascript IE错误:意外调用方法或属性访问 [英] Javascript IE error: unexpected call to method or property access

查看:201
本文介绍了Javascript IE错误:意外调用方法或属性访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,除了IE之外,它在所有的工作中(像往常一样)。它让我在Jquery中意外调用方法或属性访问,我不知道如何调试它。我一直在使用IE开发人员工具栏,这对于这个错误没用,只给了我一行12号(在jquery脚本里面)。

I have the following code and it's working (as usual) in everything but IE. It's giving me an unexpected call to method or property access in Jquery and I have no idea how to debug it. I've been using the IE developer toolbar, which is useless for this error and just gives me a line no 12 (inside the jquery script).

任何帮助都是v非常感谢:

Any help is v much appreciated:

<script type="text/javascript">
$(document).ready(function () {

    $.history.init(pageload);

    $('a[href=' + window.location.hash + ']').addClass('selected');

    $('a[rel=ajax]').click(function () {

        var hash = this.href;
        hash = hash.replace(/^.*#/, '');
        $.history.load(hash);

        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');
        $('.loading').show();

        getPage();

        return false;
    });
});

function pageload(hash) {
    if (hash) getPage();
}

function getPage() {

    hash = document.location.hash;
    hash = hash.replace(/^.*#/, '');
    var data = 'page=' + encodeURIComponent(hash);
    $.ajax({
        url: "index.php",
        type: "POST",
        data: data,
        cache: false,
        success: function (html) {
            $('.loading').hide();
            $('tbody').html(html);

        }
    });
}
</script>

这是历史插件: http://plugins.jquery.com/project/history

这是我的演示一直关注:
http://plugins.jquery.com/project/history

And here is the demo I have been following: http://plugins.jquery.com/project/history

仍然将window.location更改回document.location似乎没有什么区别

Still changing window.location back to document.location doesn't seem to make a difference

我'迷失在这一个。当我更改标签时,我正在调用它确实发布,所以它正在工作,但在IE中,设计全部被破坏,我点击的下一个链接不发布。真奇怪!!在Firefox,Opera等中运行良好。

I'm lost on this one. When I change the tag I'm calling to it does post so it's working, but in IE the design is all broken and the next links I click on don't post. Really strange!! Works fine in firefox, opera, etc.

推荐答案

我对IE抱怨它有点惊讶,但这是一件好事它确实:你在 getPage 中缺少 hash 的声明(例如,放入 var 在第一次使用之前)。

I'm a bit surprised IE complains about it, but it's a good thing it does: You're missing a declaration in getPage for hash (e.g., put var in front of the first use).

在其他人身上,它可能会创建一个隐含的全局(的属性> window 对象名为 hash ),当然是 Bad Thing (tm),但据我所知它根据规范是正确的(相关部分为8.7 [The Reference
键入]和10.1.4 [范围链和标识符解析]。)

On the others it's presumably creating an implicit global (a property of the window object called hash), which is of course a Bad Thing(tm), but as I understand it it's correct according to the specification (the relevant sections being 8.7 ["The Reference Type"] and 10.1.4 ["Scope Chain and Identifier Resolution"]).

但是,IE仍抱怨它仍然感到惊讶。它必须与jQuery调用点击处理程序的范围有关。

Still surprised IE is complaining about it, though. It must have to do with the scope in which jQuery is calling your click handler.

这篇关于Javascript IE错误:意外调用方法或属性访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆