javascript

[b]Javascript menu[/b]
  function loadOptionTabsMenu() {


var current = document.location.toString();
$('.options-tabs ul li a').each(function() {

var url = $(this).attr('href');

if (current.indexOf(url) != -1) {
alert(1);
$(this).parent().addClass("current");
} else {
$(this).parent().removeClass("current");
}
});
}

function loadSidebarMenu() {


var current = document.location.toString();
$('.nav-module-body ul li a').each(function() {

var url = $(this).attr('href');
//lert(current + " This is " + url);
if (current.indexOf(url) != -1) {
//alert(1);
$(this).parent().parent().parent().parent().removeClass("closed");
$(this).parent().parent().parent().parent().addClass("open");
}
});
}


[b]Scripts for menus[/b]
if (!document.getElementById) {
document.getElementById = function() { return null; }
}

function initMenu() {
var uls = document.getElementsByTagName("ul");
for (i = 0; i < uls.length; i++) {
if (uls[i].className == "menuList") {
decorateMenu(uls[i]);
}
}
}

function decorateMenu(menu) {
var items = menu.getElementsByTagName("li");
for (var i=0; i < items.length; i++) {
items[i].firstChild.myIndex = i;
// retain any existing onclick handlers from menu-config.xml
if (items[i].firstChild.onclick) {
items[i].firstChild.onclick=function() {
eval(items[this.myIndex].firstChild.getAttribute("onclick"));
setCookie("menuSelected", this.myIndex);
};
} else {
items[i].firstChild.onclick=function() {
setCookie("menuSelected", this.myIndex);
};
}
}
activateMenu(items);
}

function activateMenu(items) {
var activeMenu;
var found = 0;
for (var i=0; i < items.length; i++) {
var url = items[i].firstChild.getAttribute("href");
var current = document.location.toString();
if (current.indexOf(url) != -1) {
found++;
}
}

// more than one found, use cookies
if (found > 1) {
var menuSelected = getCookie("menuSelected");
if (items[menuSelected].parentNode.className == "submenu") {
items[menuSelected].firstChild.className="selected";
items[menuSelected].parentNode.parentNode.className="selected";
} else {
items[menuSelected].className+="selected";
}
} else {
// only one found, match on URL
for (var i=0; i < items.length; i++) {
var url = items[i].firstChild.getAttribute("href");
var current = document.location.toString();
if (current.indexOf(url) != -1) {
if (items[i].parentNode.className == "submenu") {
items[i].firstChild.className="selected";
items[i].parentNode.parentNode.className="selected";
} else {
items[i].className+="selected";
}
}
}
}
}

// Select the menu that matches the URL when the page loads
window.onload=initMenu;

// =========================================================================
// Cookie functions
// =========================================================================
/* This function is used to set cookies */
function setCookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
var prefix = name + "="
var start = document.cookie.indexOf(prefix)

if (start==-1) {
return null;
}

var end = document.cookie.indexOf(";", start+prefix.length)
if (end==-1) {
end=document.cookie.length;
}

var value=document.cookie.substring(start+prefix.length, end)
return unescape(value);
}

/* This function is used to delete cookies */
function deleteCookie(name,path,domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}


[b]Handle link click[/b]

$(document).ready(function(){
//$("a").click(function(event){
//alert("Thanks for visiting!");
//event.preventDefault();

//});
$("a")
.filter(".clickme")
.click(function(){
alert("You are now leaving the site.");
})
.end()
.filter(".hideme")
.click(function(){
$(this).hide();
return false;
})
.end();
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值