从 JSON Href 获取一个在 table 中工作的按钮
Get a button working in a table From JSON Href
<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 放入按钮 link?显示在同一个地方(table。我已经尝试将我可以添加的所有按钮命令添加到没有工作的代码中,我还尝试将它添加到 href 的前面和加号的前面。
山姆
链接未在HTML中自行解析。您需要改用 <a>
标签。这很脏,但是根据您的代码,最快的方法是将 append
更改为
$("table").append(""
+ "<tbody>"
+ "<tr>"
+ "<td>" + title + "</td>"
+ "<td><a href=" + href + ">" + href + "</a></td>"
+ "</td>"
+ "</tr>"
+ "</tbody>"
);
...虽然我不明白 table 的意思。
<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 放入按钮 link?显示在同一个地方(table。我已经尝试将我可以添加的所有按钮命令添加到没有工作的代码中,我还尝试将它添加到 href 的前面和加号的前面。
山姆
链接未在HTML中自行解析。您需要改用 <a>
标签。这很脏,但是根据您的代码,最快的方法是将 append
更改为
$("table").append(""
+ "<tbody>"
+ "<tr>"
+ "<td>" + title + "</td>"
+ "<td><a href=" + href + ">" + href + "</a></td>"
+ "</td>"
+ "</tr>"
+ "</tbody>"
);
...虽然我不明白 table 的意思。