![](/img/trans.png)
[英]How to make particular Li tag active on click on anchor tag inside of that li tag?
[英]How can i make a specific li to be active inside a while loop
我如何才能使特定的li
在while
循環內處於活動狀態? 指標將是GET
的值,即$subj = $_GET['subjdescr'];
我對JavaScript和CSS不好。 有人可以給我一些想法嗎? 或線索。
如果我單擊英語2,我希望英語2處於活動狀態。 否則,如果我單擊數學,該數學將處於活動狀態。
這是我的代碼。
<li><ul class="premium-menu nav nav-list collapse in">
<?php
$subj = $_GET['subjdescr'];
$sql ="SELECT enroll_ref FROM std_enrolled WHERE stud_no = '$stud_no'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)){
$enroll_ref = $row['enroll_ref'];
}
$sql3 ="SELECT DISTINCT subj_descr FROM subj_enrolled WHERE enroll_ref = '$enroll_ref'";
$results = mysqli_query($con, $sql3);
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
//i want the value of the subj_descr is equals to the value of get data $subj.
<li <?=$subj_descr=='$subj'?'class="active"':'' ?> ><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
}
?>
</ul></li>
使用staic變量進行檢查
<?php
static $i =0;
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
<li class="<?php if($i == 0) { echo 'active'; } ?>"><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
++$i;
}
?>
用你的話說
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
<li <?=$subj_descr=='English 2'?'class="active"':'' ?>><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.