這是我第二次嘗試這個問題,所以請耐心等待。包括一個JavaScript菜單使用php
你怎麼包括JS菜單到一個PHP頁面?
每當我做導航它有它的HTML一個包含語句,什麼也不顯示。
的index.php具有包括statment應該從NAV採取的代碼,並使用menu.js顯示它
這裏是從指數
<span id="container" >
<!-- NAVIGATION -->
<ul id="menu">
<?php include('nav.php')?>
</ul>
</span>
片段,並在這裏是nav.php
<li><a href="index.php" title="Portraiture Gallery" class="selected">Portraiture Gallery</a>
<ul>
<li><a href="portraiture/adults.php" title="Adults">Adults </a></li>
<li><a href="portraiture/seniors.php" title="Seniors">Seniors </a></li>
<li><a href="portraiture/infantsandchildren.php" title="InfantsandChildren">Infants and Children </a></li>
<li><a href="portraiture/multiples.php" title="Multiples">Mutiples </a></li>
<li><a href="portraiture/hisangels.php" title="Hisangels">His Angels </a></li>
</ul>
</li>
這種格式之後,因爲menu.js是該寫的。
menu.js
// JavaScript Document
// DropDownMenu by Miha Hribar
// http://hribar.info
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function prepareMenu() {
// first lets make sure the browser understands the DOM methods we will be using
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
// lets make sure the element exists
if (!document.getElementById("menu")) return false;
var menu = document.getElementById("menu");
// for each of the li on the root level check if the element has any children
// if so append a function that makes the element appear when hovered over
var root_li = menu.getElementsByTagName("li");
for (var i = 0; i < root_li.length; i++) {
var li = root_li[i];
// search for children
var child_ul = li.getElementsByTagName("ul");
if (child_ul.length >= 1) {
// we have children - append hover function to the parent
li.onmouseover = function() {
if (!this.getElementsByTagName("ul")) return false;
var ul = this.getElementsByTagName("ul");
ul[0].style.display = "block";
return true;
}
li.onmouseout = function() {
if (!this.getElementsByTagName("ul")) return false;
var ul = this.getElementsByTagName("ul");
ul[0].style.display = "none";
return true;
}
}
}
return true;
}
addLoadEvent(prepareMenu);
什麼是「JS菜單」?你能否至少展示一些你試圖得到的僞代碼? – raina77ow
所以,你將不得不提供更多的信息。 「JS菜單」是什麼意思?也許顯示代碼會有所幫助。另外,顯示你的PHP代碼會有幫助。 –