如何在html href标签中插入链接

我目前正在编写一个脚本,该脚本从 google 表格中提取数据并将其转换为 html 表。但我的谷歌表格中有链接,所以我希望这些链接可以在一个看起来不错但不知道如何做到这一点的按钮中获得。我现在有这个loob


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>';

 }

 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 Spreadsheet

var 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>';

  }


紫衣仙女
浏览 119回答 1
1回答

弑天下

您只需要将链接包装在<a>标签内即可for (var i = 0; i < entry.length; i++) {&nbsp; &nbsp; html += '<tr>';&nbsp; &nbsp; html += '<td>' + entry[i]['gsx$komponente']['$t'] + '</td>';&nbsp; &nbsp; html += '<td>' + entry[i]['gsx$name']['$t'] + '</td>';&nbsp; &nbsp; html += '<td>' + entry[i]['gsx$hersteller']['$t'] + '</td>';&nbsp; &nbsp; html += '<td>' + entry[i]['gsx$preis']['$t'] + '</td>';&nbsp; &nbsp; html += '<td><a href=' + entry[i]['gsx$link']['$t'] +&nbsp; '>' +entry[i]['gsx$link']['$t'] + '</a></td>';&nbsp; &nbsp; html += '</tr>';&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript