我已经创建了一个函数来获取网页的路径名,如果它匹配菜单项的id,那么它会添加一个css属性到div标记,显示div作为当前页面。继承人网站即时测试:http://kwp.host22.com。即时通讯使用警报来检查变量是否正确。继承人我的HTML。.css jquery属性不应用css到div标记
<div id="navigation">
<a href="index.html"><div class="navblocks" id="index.html"><p>Home</p></div></a>
<a href="cleaning.html"><div class="navblocks" id="cleaning.html"><p>Cleaning</p></div></a>
<a href="contact.html"><div class="navblocks" id="contact.html"><p>Contact Us</p></div></a>
</div>
和继承人我的jquery:
var path = window.location.pathname;
if(path === "/")
{
var pathname = path.replace("/","index.html");
}
else
{
pathname = path.replace("/","");
}
alert("pathname = " + pathname);
var id = "#" + pathname;
alert("id = " + id);
$('a').each(function()
{
var href = $(this).attr("href");
alert("href = " + href);
if (href === pathname)
{
$(id).css('box-shadow','0px 0px 20px inset');
}
,但它不是应用盒子阴影div标签。
任何帮助将不胜感激即时通讯仍然学习jquery。 谢谢