2015-09-01 31 views
0

我試圖通過比較兩個團隊的分數,突出贏家(最高分)團隊,通過添加一個類「贏家」以突出在籃球比賽中的贏家HTML元素是這樣的:比較兩個值與php,突出顯示最高

<ul class="game-result"> 
    <li class="winner"><span>Team 1</span><?php echo $team1_points; ?></li> 
    <li class=""><span>Team 2</span><?php echo $team2_points; ?></li> 
</ul> 

我使用WordPress和PHP,任何幫助將不勝感激!

感謝

回答

1

像這樣

<ul class="game-result"> 
<li <?php echo (($team1_points>$team2_points)?'class="winner"':''); ?>><span>Team 1</span><?php echo $team1_points; ?></li> 
<li <?php echo (($team2_points>$team1_points)?'class="winner"':''); ?>><span>Team 2</span><?php echo $team2_points; ?></li> 
</ul> 
0
<ul class="game-result"> 
    <li <?=($team1_points > $team2_points ? "class='winner'" : "")?> ><span>Team 1</span><?php echo $team1_points; ?></li> 
</ul> 
0
<ul class="game-result"> 
    <li <?php echo (($team1_points>$team2_points)?'class="winner"':'class=""'); ?>><span>Team 1</span><?php echo $team1_points; ?></li> 
    <li <?php echo (($team2_points>$team1_points)?'class="winner"':'class=""'); ?>><span>Team 2</span><?php echo $team2_points; ?></li> 
</ul> 

即使傳單的答案是正確的,這個人將會使你的代碼看起來你張貼在問題描述完全

相關問題