我目前正在编写一个脚本,该脚本从 google 表格中提取数据并将其转换为 html 表。但我的谷歌表格中有链接,所以我希望这些链接可以在一个看起来不错但不知道如何做到这一点的按钮中获得。我现在有这个loobfor (var i = 0; i < entry.length; i++) { html += '<tr>'; html += '<td>' + entry[i]['gsx$komponente']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$name']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$hersteller']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$preis']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$link']['$t'] + '</td>'; html += '</tr>'; } html += '</table>';这entry[i]['gsx$link']['$t']给了我链接,我只是无法让它在按钮内工作如果您知道如何解决这个问题,请帮助我这是完整的代码<!DOCTYPE html><meta charset="ISO-8859-1"> <html><body><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script>// ID of the Google Spreadsheetvar spreadsheetID = "1Xx0qGY_5Ic1KNB7m8Lu5mZqHE4XQzauvcugTVUGwgqk"; // Make sure it is public or set to Anyone with link can view var url = "https://spreadsheets.google.com/feeds/list/" + spreadsheetID + "/od6/public/values?alt=json"; // make JSON call to Google Data API$.getJSON(url, function(data) { // set global html variable var html = ''; // build table headings html += '<table>'; html += '<tr>'; html += '<th>Komponente</th>'; html += '<th>Name</th>'; html += '<th>Hersteller</th>'; html += '<th>Preis</th>'; html += '<th>Link</th>'; html += '</tr>'; // loop to build html output for each row var entry = data.feed.entry; /** ** Change to descending order ** for (var i = entry.length - 1; i >= 0; i -= 1) { */ for (var i = 0; i < entry.length; i++) { html += '<tr>'; html += '<td>' + entry[i]['gsx$komponente']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$name']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$hersteller']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$preis']['$t'] + '</td>'; html += '<td>' + entry[i]['gsx$link']['$t'] + '</td>'; html += '</tr>'; }
1 回答
弑天下
TA贡献1818条经验 获得超8个赞
您只需要将链接包装在<a>标签内即可
for (var i = 0; i < entry.length; i++) {
html += '<tr>';
html += '<td>' + entry[i]['gsx$komponente']['$t'] + '</td>';
html += '<td>' + entry[i]['gsx$name']['$t'] + '</td>';
html += '<td>' + entry[i]['gsx$hersteller']['$t'] + '</td>';
html += '<td>' + entry[i]['gsx$preis']['$t'] + '</td>';
html += '<td><a href=' + entry[i]['gsx$link']['$t'] + '>' +entry[i]['gsx$link']['$t'] + '</a></td>';
html += '</tr>';
}
添加回答
举报
0/150
提交
取消