【问题标题】:Change All Values in HTMLDIVS if Inner Value is a Negative Number如果内部值为负数,则更改 HTMLDIVS 中的所有值
【发布时间】:2016-11-13 17:07:07
【问题描述】:

我们有一个 PHP SQL 查询,它返回一个 JSON 数组,这些值被分配给 HTML 中的 DIVS。 多个返回值的最终结果如下所示:

<div id = "tdiv"> -58 </div>
<div id = "tdiv2"> -85 </div>
<div id = "tdiv3"> 58 </div>

我们正在尝试为所有具有负数的 DIV 值分配红色。

有什么想法吗?

谢谢你

【问题讨论】:

  • 先告诉我这些值是从哪里来的?请出示您的 PHP 代码。

标签: javascript php html css sql


【解决方案1】:

Attribute starts with 选择器上使用jQuery.filter

$('[id^=tdiv]').filter(function() {
  return this.textContent < 0;
}).css('color', 'red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="tdiv">-58</div>
<div id="tdiv2">-85</div>
<div id="tdiv3">58</div>

【讨论】:

  • 漂亮的脚本@Rayon,我真的很感激。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多