weixin_33725272 2016-03-05 15:02 采纳率: 0%
浏览 15

将ID设为String jQuery?

I have a jQuery function that calls an API. The result sends me back some data. There is a piece of data I need to work with.

I'm trying to replace teamId = 100 with "Blue Team" and teamId = 200 with (Read Team).

I just need a variable that checks if the ID is 100 and makes the value of the variable "blue" and if its 200 then "red"

I've got this:

        function generateTeamHtml(teamId, participants)  {
      var teamNum = "team"+teamId;
      var html = '<table id="' + teamNum + '">';
      html += '<thead>';
      html += '<tr><th colspan="2">';
      html += teamNum;
      html += '</th></tr>';
      html += '<tr><th>   Summoner Name   </th><th>   Summoner Id   </th></tr>';
      html += '</thead><tbody>';
      for ( userNum in participants) {
        var user = participants[userNum];
        var team = user.teamId;
        var summonerName = user.summonerName;
        var summonerId = user.summonerId;
        if (team == teamId) {
          html += '<tr><td>' + summonerName + '</td><td>' + summonerId + '</td></tr>';
        }
      }
      html += '</tbody></table>';
      return html;
    }

So in the table I see either "team100" or "team 200" I would like a variable called

var = teamColour

Team Colour should take "teamId" and say if the id is 100 then make "teamColour" Blue if "teamId" make "teamColour" Red.

Thankyou!

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8
      • ¥15 安卓时间管理APP,怎么做
      • ¥15 这段有什么bug 为什么总报错