gpt4 book ai didi

javascript - 无法弄清楚如何使用 jQuery 将 HTML 片段直接插入到 HTML 文档中

转载 作者:行者123 更新时间:2023-12-03 09:27:30 24 4
gpt4 key购买 nike

我已经检查了尽可能多的问题,我不断得到的答案是使用 javascript 或 jQuery 来做到这一点。所以我有我的主要 html 文件:

index.html

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>

<body>
<!-- I want to insert a paragraph here -->
<div id="a"></div>
<script>$( "#a" ).load( "insertme.html" );</script>
</body>
</html>

插入me.html

<p>Inserted into another doc!</p>

我找到了这个方法here ,据我所知,我已经以同样的方式实现了它。

那么我在这里做错了什么?为什么我的代码没有被插入?

最佳答案

首先,你缺少 jQuery。将此行添加到您的 <head></head>

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

您有 DOM 准备情况问题吗?

试试这个:

$(document).ready(function(){
$( "#a" ).load( "insertme.html" );
});

此外,请确保 insertme.html 与您的 index.html 文件位于同一文件夹中。

关于javascript - 无法弄清楚如何使用 jQuery 将 HTML 片段直接插入到 HTML 文档中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31619711/

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