0
$row->cap24hrChange
の結果に対して条件付き書式を設定しようとしています。 < 0
の場合は、値を赤色にしたい、そうでない場合は緑色にする必要があります。私はこのスクリプトから何の反応も得ていない。JavaScript内のJavaScriptの条件付き書式設定
<table><head><style>
td {text-align: right;}
</style></head><table>
<thead>
<tr>
<th>#Rank</th>
<th>Name</th>
<th>Price</th>
<th>Mkt Cap</th>
<th>Volume</th>
<th>Supply</th>
<th>24h(%)</th>
</tr>
</thead>
<tbody>
<?php function compare($a, $b) {
return intval($a->position24) - intval($b->position24);
}
$json = file_get_contents('http://www.coincap.io/front');
$data = json_decode($json);
usort($data, 'compare');
?>
<?php foreach ($data as $row) { ?>
<tr>
<td><?= $row->position24; ?></td>
<td><?= $row->long; ?></td>
<td><?= number_format($row->price, 4); ?><\td>
<td><?= number_format($row->mktcap, 2); ?><\td>
<td><?= number_format($row->volume, 2); ?><\td>
<td><?= number_format($row->supply, 2); ?><\td>
<td><?= $row->cap24hrChange; echo "<script type=\"text/javascript\"> var trTags = document.getElementsByTagName("td"); for (var i = 0; i < trTags.length; i++) { var tdEightEl = trTags[i].children[7]; if (tdEightEl.innerText < 0) {tdEightEl.style.color = "red"; } else if (tdEightEl.innerText > 0) {tdEightEl.style.color = "green"; } }</script>";?></td>
</tr>
<?php } ?>
</tbody>
</table>
EDIT非常に関連ノートで
:右(↑と↓)上のアイコンを含むようにどのように私はそのコードを回避することができ、それぞれの値> 0と< 0、のために?
EDITは(2)
は、私はそれを行うためにはJavaScriptを使用しないでください$foo = "bar".$foo
<td style="color:<?php if($row->cap24hrChange > 0){ echo "green"; $row->cap24hrChange = $row->cap24hrChange . " ";}else if($row->cap24hrChange < 0){ echo "red"; $row->cap24hrChange = $row->cap24hrChange . " ";}?>"><?= $row->cap24hrChange;?></td>
これは本当にすてきです!ありがとう=) – tklein