gpt4 book ai didi

jquery - 用 jquery 用 html 文本写 json 数据的例子

转载 作者:太空狗 更新时间:2023-10-29 15:05:58 26 4
gpt4 key购买 nike

我是编程初学者,我希望有人能给我一个例子,告诉我如何用HTML 文本编写JSON 数据

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1>antar<h2>
<script>
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
document.open();
document.write('Latitude: ' + data.latitude + '\nLongitude: ' + data.longitude + '\nCountry: ' + data.address.country);
document.close();
});
</script>
</body>
</html>

最佳答案

您可以在您的 html 中添加如下内容:

 <h2 id='lat'></h2>
<h2 id='long'></h2>
<h2 id='country'></h2>

然后将您的脚本重构为:

$(document).ready(function(){

$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {

$("#lat").text(data.latitude);
$("#long").text(data.longitude);
$("#country").text(data.country);

});
});

​Here a working example you can play with .

关于jquery - 用 jquery 用 html 文本写 json 数据的例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14100323/

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