繁体   English   中英

jQuery .load()不起作用

[英]jquery .load() doesn't work

我似乎无法让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上)。 一定有明显的东西我想念...?

加载功能在jquery 1.5版本中被破坏。 您可以在http://bugs.jquery.com/ticket/8125找到该故障单。 在版本1.5.1中已修复此问题。 您可以在http://code.jquery.com/jquery-git.js上找到包含所有最新修复程序的最新jquery版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM