好的,这是我的问题。我有一个正在运行的 php 文件,它可以单独拉出我的菜单以及所有内容。因此,例如加载我的 Index.php 会加载 index.php menu.php 和一个 dropdown.js 文件。菜单正在工作并进行下拉。我的问题是我想调用一类导航并列出“li > a > id”名称,这些名称将是 Home、关于我们等……我尝试了很多不同的方法,但似乎无法弄清楚为什么我不能在 jquery 中找出一个简单的脚本来执行此操作。有人有什么建议吗?下面是我的菜单页面代码。
<div id="nav" class="nav">
<ul id="sddm">
<li><a class="navigation" id="Home" href="index.php" onMouseOver="mopen('m1')" onMouseOut="mclosetime()">Home</a>
<div id="m1" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
</div>
</li>
<li><a class="navigation" href="station_history.php" onMouseOver="mopen('m2')" onMouseOut="mclosetime()">Station History</a>
<div id="m2" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
</div>
</li>
<li>
<a class="navigation" href="Apparatus.php" onMouseOver="mopen('m3')" onMouseOut="mclosetime()">Apparatus</a>
<div id="m3" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
<a class="navigation" href="truck_history.php">Truck History</a>
</div>
</li>
<li>
<a class="navigation" href="photos.php" onMouseOver="mopen('m4')" onMouseOut="mclosetime()">Photos</a>
<div id="m4" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
</div>
</li>
<li>
<a class="navigation" href="news_events.php" onMouseOver="mopen('m5')" onMouseOut="mclosetime()">News & Events</a>
<div id="m5" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
</div>
</li>
<li>
<a class="navigation" href="Station_members.php" onMouseOver="mopen('m6')" onMouseOut="mclosetime()">Station Members</a>
<div id="m6" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
</div>
</li>
<li>
<a class="navigation" href="education.php" onMouseOver="mopen('m7')" onMouseOut="mclosetime()">Education</a>
<div id="m7" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()">
<a class="navigation" href="SiteID">Station Tours</a>
<a class="navigation" href="SiteID">Fire Extinguisher</a>
<a class="navigation" href="SiteID">First Aid & CPR</a>
<a class="navigation" href="SiteID">Smoke Alarms</a>
</div>
</li>
<li>
<a class="navigation" href="SiteID" onMouseOver="mopen('m8')" onMouseOut="mclosetime()">Contact Us</a>
<div id="m8" onMouseOver="mcancelclosetime()" onMouseOut="mclosetime()"> </div>
</li>
</ul>
</div>
</div>
这是我试图为不起作用的警报而做的代码。
//导航
$("a.navigation").click(function () {
alert("hello");
});
终于弄清楚什么代码起作用了。这是我使用的,以防其他人遇到此问题。感谢所有帮助过的人!!!
//navigation
$(document).ready(function() {
$("a.navigation").click(function () {
alert("hello");
})
});