问题描述
我似乎无法使jquery的.load()函数起作用。必须是简单的我缺少...基本上只是尝试将more.html的片段加载到index.html。
i can't seem to get jquery's .load() function to work. must be something simple i'm missing...basically just trying to load a fragment of more.html into 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上)。必须有一些显而易见的东西我错过了吗?
i see both the alerts -- the script is being executed, and the callback is being called (i.e. the load is completing). however, the contents of do not change. i've tried on safari, chrome, and firefox (all on OSX). there must be something obvious i'm missing...?
推荐答案
在jquery 1.5版本中,load函数被破坏了。您可以在找到错误提示。这在1.5.1版中已得到修复。您可以在
The load function is broken in jquery 1.5 release. You can find the bug ticket at http://bugs.jquery.com/ticket/8125. This is fixed in version 1.5.1. You can find the very latest jquery release with all the latest fixes including load() at http://code.jquery.com/jquery-git.js
这篇关于jquery .load()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!