我有一個母版頁中的菜單項..我用javascript來改變類,當點擊..它改變了一秒類,但當其重定向到其他頁面它成爲同..任何想法如何,我應該做chaning在母版頁中的菜單項的類
我沒有獲得完整的代碼儀式,但現在它是這樣的(我已經使用了一些警告框,只是爲了看看發生了什麼..)
<style>
test1{ color: red;
height:1000px;
font-size:5px ;
background-color:Aqua;
}
test2
{ font-family:Kozuka Mincho Pro M;
color: red;
font-size: 5px }
<script type="text/javascript">
var lastid = "";
function myFunc(id) {
alert(id);
if (lastid != "") {
document.getElementById(lastid).removeAttribute("class", "test2");
document.getElementById(lastid).setAttribute("class", "test1");
var a = document.getElementById(lastid);
alert(a.getAttribute("class"));
}
var element = document.getElementById(id);
document.getElementById(id).setAttribute("class", "test2");
var cssid = id;
$("#" + id).addClass('test1');
alert(document.getElementById(id).getAttribute("class"));
lastid = id;
}
</script>
<li id="firstry" onclick="myFunc(this.id);" ><a href="master-child.aspx"> Click</a> </li>
如果你想在類值跨頁堅持,你需要發在某處(如cookie,會話或數據庫)撕裂類的價值(因爲它與用戶有關)。既然你是用javascript來做這件事,那麼cookie會是最容易的。 – MikeSmithDev