Javascript IE 错误:对方法或属性访问的意外调用 [英] Javascript IE error: unexpected call to method or property access
问题描述
我有以下代码,它在除 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).
非常感谢任何帮助:
<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
),这当然是一个 坏事(tm),但据我所知,它根据规范是正确的(相关部分为 8.7 [参考类型"] 和 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屋!