这是我对这个问题的第二次尝试,请耐心等待。
如何将JS菜单包含在php页面中?
每当我为导航包含一个包含html的包含声明时,都不会显示任何内容。
index.php有一个include语句,应该从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);
答案 0 :(得分:0)
您是否检查过PHP在运行时可能生成的任何错误消息?
并非所有PHP错误消息都会显示在浏览器中(具体取决于您的HTTP配置),因此检查通常位于access.log文件旁边的error.log文件总是有帮助的。