簡體   English   中英

添加指向腳本代碼的鏈接

[英]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 = [];

  });
}   

這里是運行代碼腳本

我要完成的工作是向“ Cnames”變量中包含的每個“符號”添加鏈接。 鏈接類似於“ https://www.example.com/chart/?symbol=Ticker ”,其中“ Ticker”是我當時要單擊的“符號”。

因此,例如,當我單擊TSLA時,我希望它會打開一個完全指向“ https://www.example.com/chart/?symbol=TSLA ”的彈出窗口(如window.open函數)。
除“ =”符號后的最后一個單詞外,該鏈接對於每個人都是平等的。
是否可以向我展示一部分代碼可以做到這一點?

我想你需要這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM