我在使用IE8獲取我的一個網站頁面時遇到了一些問題。它在IE9,Safari(Mac電腦&)& Firefox(Mac)中正常工作。我使用的是find(tag1).html(tag1)
調用序列做了標題替換,但我得到在IE8以下錯誤,當我在IE腳本調試器調試它,這在html(tag2)
功能:jQuery .find()錯誤:「意外調用方法或屬性訪問」
Unexpected call to method or property access
的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中?