作者samuel1201 (samuel1201)
看板PHP
標題[請益] css被php的迴圈判斷式卡住
時間Sun Aug 28 02:23:12 2016
大家好,
我有個dropdown menu 套件模組
if (in_array($item->id, $path)) {
$class .= ' active';
}
製作出來的選單, active時選單會自動打開
模組可以製作出N個選單出來
有的選單需要自動打開 但有些選單我並不需要他自動打開
目前我產出的menu 假設是 menu1, menu2, menu3.....etc
$item->id 會自動帶入
我希望 menu3 可以不要有 active 這個 class 加入
不曉得可以透過指定 id 的方法 寫進 if 的 loop 裡面嗎?
例如 $item->menu3 $class .=''; 就空著不要加入active 的class
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.225.111.251
※ 文章網址: https://webptt.com/m.aspx?n=bbs/PHP/M.1472322196.A.468.html
1F:推 ns1234: if(in_array($name,$auto_active) and in_array($id..)) ? 08/28 02:43
2F:→ samuel1201: 不太理解 T_T 08/28 03:02
3F:推 ns1234: 把你要自動打開的menu寫成一個array,array('menu1','menu2 08/28 03:11
4F:→ ns1234: if(這個item在是要自動打開的 and in_array($id,$path)) 08/28 03:14
5F:→ ns1234: 就加class="active" 08/28 03:14
6F:→ ns1234: 後面的in_array是你原本的條件 08/28 03:16
7F:→ samuel1201: if (in_array('classID') and in_array($item->id, $p 08/28 03:49
8F:→ samuel1201: $path)) 08/28 03:49
9F:→ samuel1201: 這樣寫對嗎? 把要自動打開的放到 classID ? 08/28 03:50
10F:→ samuel1201: 不好意思我是美術設計 想好久 :p 08/28 03:50