わかりました、私はこのコードを持っています
//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."' />
今、私は属性「ページ」の値を「現在のページ」のIDを持つ非表示の入力フィールドの値に一致する要素にクラス「アクティブ」を追加したいと考えています。 jqueryで作成するので、コードをここに示します。
$(document).ready(function(){
//get the value of the hidden input field
$page = $('#currentpage').val();
//now im stuck here ..
});
ID が「currentpage」の非表示フィールドの値と一致する属性「page」の値を持つ、指定された要素にクラスを追加する方法がわかりません
例えば:
<input type='hidden' id='currentpage' value='home' />
要素の属性「ページ」に基づいて、アクティブなクラスを追加する必要があるため、これは次のようになります。
<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: 私はアイデア、提案、推奨事項をオープンにしています。