[請益] css被php的迴圈判斷式卡住

看板PHP作者 (samuel1201)時間9年前 (2016/08/28 02:23), 編輯推噓2(209)
留言11則, 2人參與, 最新討論串1/1
大家好, 我有個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://www.ptt.cc/bbs/PHP/M.1472322196.A.468.html

08/28 02:43, , 1F
if(in_array($name,$auto_active) and in_array($id..)) ?
08/28 02:43, 1F

08/28 03:02, , 2F
不太理解 T_T
08/28 03:02, 2F

08/28 03:11, , 3F
把你要自動打開的menu寫成一個array,array('menu1','menu2
08/28 03:11, 3F

08/28 03:14, , 4F
if(這個item在是要自動打開的 and in_array($id,$path))
08/28 03:14, 4F

08/28 03:14, , 5F
就加class="active"
08/28 03:14, 5F

08/28 03:16, , 6F
後面的in_array是你原本的條件
08/28 03:16, 6F

08/28 03:49, , 7F
if (in_array('classID') and in_array($item->id, $p
08/28 03:49, 7F

08/28 03:49, , 8F
$path))
08/28 03:49, 8F

08/28 03:50, , 9F
這樣寫對嗎? 把要自動打開的放到 classID ?
08/28 03:50, 9F

08/28 03:50, , 10F
不好意思我是美術設計 想好久 :p
08/28 03:50, 10F

08/28 03:53, , 11F
貼我原本的程式碼 http://imgur.com/a/xt3ZZ
08/28 03:53, 11F
文章代碼(AID): #1NmTgKHe (PHP)
文章代碼(AID): #1NmTgKHe (PHP)