好的,我有这个代码
//start our session
session_start();
//check if there is a page request
if (isset($_GET['page']))
{
//if there is a request page then get it and put it on a session variable and sent back the data that was requested.
$_SESSION['page'] = $_GET['page'];
$currentpage = $_SESSION['page'];
}
//if there is no request then..
else
{
$_SESSION['page'] = "home"; //if there is no request page then we literally tell that we are in the main page so we session will be home
$currentpage = $_SESSION['page'];
}
//echo a hidden input fields that hold the value of current page which will be accessed by the jquery for adding classes of the match value in the attribute 'page' of the element base on the value that the hidden input field has
echo "<input type='hidden' id='currentpage' value='".$currentpage."' />
现在,我想向元素添加一个“active”类,该元素将属性“page”的值与 ID 为“currentpage”的隐藏输入字段的值相匹配,为了做到这一点,我更喜欢在 jquery 上制作它,所以这是代码。
$(document).ready(function(){
//get the value of the hidden input field
$page = $('#currentpage').val();
//now im stuck here ..
});
我不知道如何在指定元素上添加一个类,该类的属性“page”的值与 id 为“currentpage”的隐藏字段的值相匹配
例如:
<input type='hidden' id='currentpage' value='home' />
因此,应根据元素的 attr“页面”添加活动类,因此应该如下所示。
<ul>
<li><a page="home" href="index.php" class="active">home</a></li> <!--as you can see on this part an active class has been added thats because the value of the attr page of this element is match to the value of the hidden input fields which has the id of 'currentpage'-->
<li><a page="gallery" href="index.php?page=gallery">gallery</a></li>
<li><a page="about" href="index.php?page=about">about</a></li>
<li><a page="contact" href="index.php?page=contact">contact</a></li>
</ul>
希望有人能给我一些可以帮助解决当前问题的东西,提前致谢。
PS:我对想法、建议和建议持开放态度。
Like so:
$("a[page="+$page+"]").addClass("active");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)