【问题标题】:jquery .load() doesn't workjquery .load() 不起作用
【发布时间】: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


    【解决方案1】:

    加载功能在 jquery 1.5 版本中被破坏。您可以在http://bugs.jquery.com/ticket/8125 找到错误票。这在版本 1.5.1 中已修复。你可以在http://code.jquery.com/jquery-git.js找到包含所有最新修复的最新 jquery 版本,包括 load()。

    【讨论】:

    • aiaiaiai。那么这将解释它。尝试在 jquery 论坛上发布相同的问题,但一无所获。我知道stackoverflow会给我爱。谢谢!
    • 在 jquery 1.6.2 中的加载仍然被破坏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多