简体   繁体   中英

add a link to a script code

I have this script that for now has static values:

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

  });
}   

Here the running code script .

What i want to accomplish is to add a link to every "symbol" contained in "Cnames" var. The link is something like " https://www.example.com/chart/?symbol=Ticker ", where "Ticker" is the "symbol" that i'm clicking in that moment.

So for example, when i click on TSLA, i want that it will open a popup window (like a window.open function) that point exactly to " https://www.example.com/chart/?symbol=TSLA ".
The link will be equal for everyone, except for the last words after the "=" symbol.
Is it possible to show me a portion of code tha can to do that?

我想你需要这个:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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