【发布时间】:2011-08-06 02:37:34
【问题描述】:
我似乎无法让 jquery 的 .load() 函数工作。一定是我缺少的一些简单的东西......基本上只是试图将 more.html 的片段加载到 index.html 中。
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.5.js" />
<title>Test</title>
<script type="text/javascript">
$(document).ready(function () {
alert("jquery script executing...");
$('#foo').load('more.html #bar', loadComplete);
});
function loadComplete (response, status, xhr) {
alert("load complete.");
}
</script>
</head>
<body>
<div id="foo">
foo foo foo
</div>
</body>
</html>
more.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>More</title>
</head>
<body>
<div id="bar">
bar bar bar
</div>
</body>
我看到了两个警报——脚本正在执行,回调正在被调用(即加载正在完成)。但是,内容不变。我试过 safari、chrome 和 firefox(都在 OSX 上)。一定有什么明显的我遗漏了...?
【问题讨论】:
标签: javascript jquery load