【问题标题】:stockquote api, fail to printing text colorstockquote api,无法打印文本颜色
【发布时间】:2019-02-22 19:31:54
【问题描述】:

我为 BSE 和 BSE 证券交易所创建了实时 API,它运行良好并提供实时股票价格。是的,我正在使用 SENSEX api 并尝试根据以下要求更改文本颜色:

如果当前时间速率大于之前的秒速率,则为绿色,反之亦然,然后为红色..

如果当前汇率等于先前汇率。然后颜色没有变化。因为它是颜色。

这是我在控制台中的 API 的结果:

{lastprice: "37,290.67", changed: "-294.84", open: 37, low: "37,242.85", high: "37,745.44",…}

这是我的 AJAX 代码:

setInterval(function() {
  $.ajax({
    type: "post",
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    url: "{{url('live/change_stoke_market_value_live')}}",
    data: {
      "_token": "{{ csrf_token() }}"
    },
    dataType: 'json',
    success: function(res) {
      if (!res) {
        alert('Something went wrong')
      } else {

        console.log(res)

        $('#sensex').html(

          ' <div class="float-right">\n' +
          '        <i class="mdi mdi-account-multiple widget-icon"></i>\n' +
          '        </div>\n' +
          '        <h5 class="text-muted font-weight-normal mt-0" title="Number of Customers">SENSEX</h5>\n' +
          '        <h4 class="mt-3 mb-3">' + res.lastprice + ' (' + res.changed + ')</h4>\n'


        )
        if (res.lastprice.indexOf("+") != -1) {

          document.getElementById("sensex").className = "greenText";
        } else {


          document.getElementById("sensex").className = "redText";
        }

      }
    }
  });
}, 1000);
.greenText {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: rgb(83, 241, 83);
  text-decoration: none;
}

.redText {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: Red;
  text-decoration: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="nav-item dropdown">
  <a id="sensex"></a>
</li>

我不知道出了什么问题……API 和 RATE 工作正常,但是……没有颜色变化

【问题讨论】:

  • 你有这个直播吗?
  • 好的,如果要我帮你调试,我需要看看。
  • 我在这里,但没有简单的方法可以触发我知道的聊天。
  • 你在吗? @SergChernata

标签: html css ajax api laravel-5


【解决方案1】:

这最终成为一个非常简单的css 特异性问题。我们通过将!important 添加到类中的文本颜色声明来解决问题。

.greenText {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: rgb(83, 241, 83) !important;
  text-decoration: none;
}

.redText {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: Red !important;
  text-decoration: none;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2014-03-18
    相关资源
    最近更新 更多