gpt4 book ai didi

javascript - 字符串 str 始终为空,尽管它充满了来自 .geojson 文件的数据,你知道吗?

转载 作者:行者123 更新时间:2023-11-30 09:59:09 25 4
gpt4 key购买 nike

<!DOCTYPE html>
<html>

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function() {

$("#p1").load("reporting/data.geojson").toString();
var str = document.getElementById("p1").innerHTML;
document.getElementById("p2").innerHTML = str;
});
</script>
</head>

<body>

<div id="div1">
<h2>try</h2>
</div>
<p id="p1"></p>
<p id="p2"></p>
</body>

</html>

这是代码,p1 清楚地显示在屏幕上,但我的实际问题是我无法用它填充字符串,“也许加载函数是最后一个 Action ,我不知道”这有点新。我需要将 .geojson 文本放在一个字符串中,或​​者任何其他提取坐标的方式都会省去字符串编辑的麻烦。谢谢 iij 提前

最佳答案

您需要使用load回调#p1获取数据。

load 方法是异步的,因此代码不会等待数据加载并执行下一条语句。

$(document).ready(function() {

$("#p1").load("reporting/data.geojson", function() {
var str = document.getElementById("p1").innerHTML;
document.getElementById("p2").innerHTML = str;
});
});

当你使用 jQuery 时,你可以使用 html()

$(document).ready(function () {

$("#p1").load("reporting/data.geojson", function () {
$('#p2').html($('#p1').html());
});
});

关于javascript - 字符串 str 始终为空,尽管它充满了来自 .geojson 文件的数据,你知道吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32578821/

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