gpt4 book ai didi

javascript - 无法通过 jquery 附加 HTML 文件

转载 作者:行者123 更新时间:2023-11-28 02:43:37 25 4
gpt4 key购买 nike

我知道这个问题已经被问过好几次了,但我遇到了这个问题。我想在 index.html 文件中附加 otherpage.html 的内容

我的 index.html 代码是

<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.get("otherpage.html", function (data) {
$("#appendToThis").append(data);
});
});
</script>
</head>
<body>
<div id="appendToThis"></div>
</body>

我的 otherpage.html 代码是

<p>This is second page.</p>

当我打开 Index.html 时,我看到一个空白页面。任何人都可以指出错误在哪里..提前致谢

最佳答案

我相信这是您正在寻找的另一个已回答的问题:

How to load another html file using JS

此示例使用了其他人在此线程中提出的一些要点。它将需要 JS 的 AJAX 请求来读取文件、解析它,然后替换该信息。该示例使用 onClick 方法,但您应该能够使用您喜欢的任何方法(包括加载时)来执行您定义的 AJAX 调用函数。

关于javascript - 无法通过 jquery 附加 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42516492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com