在脚本代码中添加 link

add a link to a script code

我有这个脚本,现在有静态值:

var Lines = [];

var addLine = function(symbol, price, change, percent) {
  Lines.push('<tr>' +
    '<td class="symbol" >' + symbol  + '</td>' +
    '<td class="price"  >' + price   + '</td>' +
    '<td class="change" >' + change  + '</td>' +
    '<td class="percent">' + percent + '</td>' +
    '</tr>');
};

//  function to get data
function StockPriceTicker() {
  var Symbol = "",
      CompName = "",
      Price = "",
      ChnageInPrice = "",
      PercentChnageInPrice = "";

  var CNames = "TSLA,HPQ,VRSK,CERN,KHC,EXPD";
  var flickerAPI = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + CNames + "%22)&env=store://datatables.org/alltableswithkeys";

  var StockTickerXML = $.get(flickerAPI, function(xml) {
    $(xml).find("quote").each(function() {
      Symbol = $(this).attr("symbol");
      $(this).find("Name").each(function() {
        CompName = $(this).text();
      });
      $(this).find("LastTradePriceOnly").each(function() {
        Price = $(this).text();
      });
      $(this).find("Change").each(function() {
        ChnageInPrice = $(this).text();
      });
      $(this).find("PercentChange").each(function() {
        PercentChnageInPrice = $(this).text();
      });

      var PriceClass = "GreenText",
          PriceIcon = "up_green";

      if (parseFloat(ChnageInPrice) < 0) {
        PriceClass = "RedText";
        PriceIcon = "down_red";
      }


      var htmlSymbol,
          htmlPrice,
          htmlChange,
          htmlPercent;


      htmlSymbol = "<span class='quote'>" + Symbol + " </span></span>";
      htmlPrice = "<span class='" + PriceClass + "'>";
      htmlPrice = htmlPrice + parseFloat(Price).toFixed(2) + " ";

      htmlChange = parseFloat(Math.abs(ChnageInPrice)).toFixed(2) + "<span class='" + PriceIcon + "'></span>";

      htmlPercent = parseFloat(Math.abs(PercentChnageInPrice.split('%')[0])).toFixed(2) + "%";


      // use here the function defined above.
      addLine(htmlSymbol, htmlPrice, htmlChange, htmlPercent);

    });



    $body.empty().html(Lines.join(''));

    // we reset the content of Lines for the next interval
    Lines = [];

  });
}   

这里是running code script.

我想要完成的是向 "Cnames" var 中包含的每个 "symbol" 添加一个 link。 link 类似于“https://www.example.com/chart/?symbol=Ticker”,其中 "Ticker" 是我当时点击的 "symbol"。

因此,例如,当我单击 TSLA 时,我希望它会打开一个弹出窗口 window(如 window.open 函数),该窗口恰好指向“https://www.example.com/chart/?symbol=TSLA”。
link 对每个人都是平等的,除了“=”符号后面的最后一个词。
可以给我看一部分代码吗?

我猜你需要这个:

'<td class="symbol" > <a href="https://www.example.com/chart/?symbol=' + ($(symbol).text())  + '" target="_blank">' + symbol + '</a> </td>'