【发布时间】:2011-10-25 04:05:05
【问题描述】:
我在使用 IE8 获取我的网站页面之一时遇到了一些问题。它在 IE9、Safari(PC 和 Mac)和 Firefox (Mac) 中运行良好。我正在使用find(tag1).html(tag1) 调用序列来进行标题替换,但是当我在 IE 脚本调试器中调试它时,在 IE8 中出现以下错误,而这在 html(tag2) 函数中:
对方法或属性访问的意外调用
find(tag1) 函数似乎返回封闭对象(即#sidebar),而不是嵌套对象#sidebarheader,这会在以后调用html(tag2) 时导致问题。
我创建了一个有代表性的测试用例如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery .find() test case</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script type="text/javascript">
function UpdateHeader() {
$('#sidebar').find('header').html("New Title"); // IE8, nesting div's in the find fct. will not discover the child div
}
document.ready = UpdateHeader;
</script>
</head>
<body>
<div style="height: 400px; width: 390px">
<div id="jqm-home">
<div id="page">
<div id="sidebar">
<div id="sidebarheader">
<header>Old Title</header>
</div>
</div>
</div>
<p onclick="UpdateHeader();">Click to update title</p>
</div>
</div>
</body>
</html>
这里是 jsFiddle 测试用例:
有没有人建议如何让它在 IE8 中工作?
【问题讨论】:
标签: javascript jquery internet-explorer-8