javascript - 从 JSON Href 获取在表中工作的按钮

标签 javascript jquery html ajax json

    <table class="pull-left table table-fill">
  <thead>
  <tr>
    <th class="table-hover">Name</th>
    <th class="table-hover">Price</th>

</tr>
</thead>
</table>


</body>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>

      $.ajax({
          type: 'GET',
          crossDomain: true,
          dataType: 'jsonp',
          url: 'api link here',
          success: function (json) {
               //var json = $.parseJSON(data);
               for(var i =0;i < json.results.collection1.length;i++) {
                 var title = json.results.collection1[i].EventsUK.text;
                 var href = json.results.collection1[i].EventsUK.href;
             $("table").append("<tbody><tr><td>"+title+"</td><td>"+href+"</td></tr></tbody>");
           }
     },
     error: function(error){
          console.log(error);
     }
   });
</script>

我从网站收到了 href。我如何将 href 放入按钮链接中?要显示在同一个位置(表格)。我尝试将所有按钮命令添加到不起作用的代码中,我还尝试将其添加到 href 前面和加号前面。

山姆

最佳答案

HTML 中的链接无法自行解析。您需要使用<a>标签代替。这是非常脏的,但是根据您的代码,最快的技巧是更改您的 append进入

$("table").append(""
    + "<tbody>"
    + "<tr>"
    + "<td>" + title + "</td>"
    + "<td><a href=" + href + ">" + href + "</a></td>"
    + "</td>"
    + "</tr>"
    + "</tbody>"
);

...虽然我不明白该表的含义。

关于javascript - 从 JSON Href 获取在表中工作的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28115172/

相关文章:

html - 如何仅使用 html 和 css 在导航栏的右边框中添加空间?

javascript - Chrome 扩展内容脚本是否可以对本身是 Chrome 扩展一部分的 html 文件发出 jQuery AJAX 请求?

javascript - 如何使用 Angular JS 在 x-editable 中同时选中两个复选框

javascript - 将加号 "+"添加到 JQuery 输出中的正数

javascript - 缓存 JQuery UI-Tabs Ajax 加载的内容?

HTML5 iFrame 无缝属性

javascript - Background Size : Contain, 缩放后得到Size

javascript - 为什么javascript中的module.export函数中的变量被分配为 'this'

javascript - 如何在 Angular js 中使用服务将数字加倍?

javascript - 在 Google Charts (Gauge) 中使用变量作为值