将Javascript警报转换为HTML

时间:2017-10-26 17:49:12

标签: javascript jquery html innerhtml

<script> $.getJSON("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_month.geojson", function(json) 
      {console.log(json);  var newString = JSON.stringify(json, null, 0)var obj = JSON.parse(newString);alert(obj.features.length) })</script>

有帮助写了一些代码,在我的网站www.livehazards.com上提出了一个警告框。

如何将这行代码转换为html,以便在侧栏中显示相同的句子

提前致谢

 alert("There have been  " + obj.features.length + "  Earthquakes in the last month");

1 个答案:

答案 0 :(得分:0)

使用jQuery(因为看起来你在那里使用jQuery):

$("#elementID").text("There have been " + obj.features.length + " Earthquakes in the last month");

其中elementID是您希望文本在其中的元素的ID。