gpt4 book ai didi

jquery - 使用 jQuery 将 html 加载到页面中

转载 作者:行者123 更新时间:2023-11-28 00:06:29 25 4
gpt4 key购买 nike

我有一个页面,我需要在单击文件夹时将不同的 html 加载到 div 中。这种工作方式是因为单击...div 会打招呼。我尝试用 html 替换“hello”并使用 ' 而不是“但它不起作用。我还尝试使用 .load 和 .get 命令从外部文件读取。这是关键部分和我的 .get和 .load 命令,无论我做什么都不起作用。

他们有另一种方法吗?或者有什么方法可以使用我所拥有的。

jQuery:

$("#one").click(function() {
$("#read").html("hello");
});

HTML:

  <div id="read">

</div>

获取失败:

$("#one").click(function() {
$.get('readfrom/one.txt')
.success(function(data) {
$('#read').html(data);
});
});

加载失败:

$("#one").click(function() {
$('#read').load('readfrom/one.txt');
});

最佳答案

你需要这样做:

$(document).ready(function() {
$("#one").click(function() {
$.ajax({
url : "readfrom/one.txt",
dataType: "text",
success : function (data) {
$("#read").html(data);
}
});
});
});

关于jquery - 使用 jQuery 将 html 加载到页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18177686/

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