繁体   English   中英

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

[英]How to insert link in to html href tag

我目前正在编写一个脚本,该脚本从 Google 表格中提取数据并将其转换为 html 表格。 但我在我的 google 表格 tabele 中有链接,所以我希望这些链接得到但在一个看起来不错的按钮中,但无法弄清楚如何做到这一点。 我目前有这个 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>';
  }
  html += '</table>';

  // output html
  $('.console').html(html);
});

// loading animation
var loading = $('.loading');
loading.hide();
$(document)
  .ajaxStart(function() {
    loading.show();
  })
  .ajaxStop(function() {
    loading.hide();
  });



</script>



<div class="console"></div>

<div class="loading">
  
</div>





</body>
</html> 

您只需要将链接包裹在<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>'; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM