【问题标题】:Javascript doesnt output the result at the same lineJavascript不在同一行输出结果
【发布时间】:2020-04-29 02:31:02
【问题描述】:

这段代码有点问题

  <div id="ip"></div>
<div id="city"></div>
<div id="land"></div>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    $.get("https://api.ipdata.co?api-key=test", function (response) {
        $("#ip").html("IP: " + response.ip);
        $("#city").html(response.city + ", " + response.region);
        $("#land").html(response.country_name + ", " + response.region);

        $("#response").html(JSON.stringify(response, null, 4));
    }, "jsonp");

</script>

我希望结果应该显示在同一行而不是这样 enter image description here 我尝试了一切,但它就这样结束了。我需要帮助!我需要IP地址和城市名称应该在同一行

【问题讨论】:

  • 我可以使用 Aarons 帮助解决这个问题,我尝试使用标签 span 也有效^^

标签: javascript html asp.net ip


【解决方案1】:

像这样?为什么不将所有内容放在同一个 div 中,这对我来说似乎是更清洁的解决方案,也是我的方法。

<div id="wrapper"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
  $.get("https://api.ipdata.co?api-key=test", function(response) {
    $("#wrapper").append("IP: " + response.ip);
    $("#wrapper").append(" " + response.city + ", " + response.region);
    $("#wrapper").append(" " + response.country_name + ", " + response.region);

    $("#response").html(JSON.stringify(response, null, 4));
  }, "jsonp");
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    相关资源
    最近更新 更多