// JavaScript Document
window.onload = function(){
//子菜单添加事件
var menuList = document.getElementById("subMenu").getElementsByTagName("a");
for(var i=0;i<menuList.length;i++){
EventUtil.addEventHandler(menuList[i],"click",menuFocus);
}
//物品详情
var goods = document.getElementById("list").getElementsByTagName("li");
for(var i=0;i<goods.length;i++){
var picDiv = goods[i].getElementsByTagName("img")[0];
if(typeof picDiv != "undefined"){
EventUtil.addEventHandler(picDiv,"mouseover",goodsOpen);
EventUtil.addEventHandler(picDiv,"mouseout",goodsOut);
}
}
}
//子菜单激活
function menuFocus(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var menuList = document.getElementById("subMenu").getElementsByTagName("a");
_target.blur(); //去掉FF的焦点框
EventUtil.preventDefault(_event); //停止默认事件
for(var i=0;i<menuList.length;i++){
if(menuList[i]==_target){
menuList[i].className = "on";
}else{
menuList[i].className = "";
}
}
}
//物品详情
function goodsOpen(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var tips = _target.nextSibling;
var tipsPar = _target.parentNode;
if(typeof tips != "undefined"&&tips.style.display=="none"){
tips.style.display = "block";
}
tipsPar.style.zIndex = "9"; //解决IE6,IE7 zindex解释不正确
}
function goodsOut(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var tips = _target.nextSibling;
var tipsPar = _target.parentNode;
if(typeof tips != "undefined"&&tips.style.display=="block"){
tips.style.display = "none";
}
tipsPar.style.zIndex = "0";
}
//------------------------以下为公用---------------------------------//
//事件对象
var EventUtil = new Object;
//添加事件
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
//移除事件
EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.removeEventListener) {
oTarget.removeEventListener(sEventType, fnHandler, false);
} else if (oTarget.detachEvent) {
oTarget.detachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = null;
}
};
//获取event对象
EventUtil.getEvent = function(event) {
return event?event:window.event;
};
//获取事件目标
EventUtil.getTarget = function(event) {
return event.target || event.srcElement;
}
//停止默认事件
EventUtil.preventDefault = function(event){
if(event.preventDefault){
event.preventDefault();
}else{
event.returnValue = false;
}
}
window.onload = function(){
//子菜单添加事件
var menuList = document.getElementById("subMenu").getElementsByTagName("a");
for(var i=0;i<menuList.length;i++){
EventUtil.addEventHandler(menuList[i],"click",menuFocus);
}
//物品详情
var goods = document.getElementById("list").getElementsByTagName("li");
for(var i=0;i<goods.length;i++){
var picDiv = goods[i].getElementsByTagName("img")[0];
if(typeof picDiv != "undefined"){
EventUtil.addEventHandler(picDiv,"mouseover",goodsOpen);
EventUtil.addEventHandler(picDiv,"mouseout",goodsOut);
}
}
}
//子菜单激活
function menuFocus(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var menuList = document.getElementById("subMenu").getElementsByTagName("a");
_target.blur(); //去掉FF的焦点框
EventUtil.preventDefault(_event); //停止默认事件
for(var i=0;i<menuList.length;i++){
if(menuList[i]==_target){
menuList[i].className = "on";
}else{
menuList[i].className = "";
}
}
}
//物品详情
function goodsOpen(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var tips = _target.nextSibling;
var tipsPar = _target.parentNode;
if(typeof tips != "undefined"&&tips.style.display=="none"){
tips.style.display = "block";
}
tipsPar.style.zIndex = "9"; //解决IE6,IE7 zindex解释不正确
}
function goodsOut(event){
var _event = EventUtil.getEvent(event);
var _target = EventUtil.getTarget(_event); //目标对象
var tips = _target.nextSibling;
var tipsPar = _target.parentNode;
if(typeof tips != "undefined"&&tips.style.display=="block"){
tips.style.display = "none";
}
tipsPar.style.zIndex = "0";
}
//------------------------以下为公用---------------------------------//
//事件对象
var EventUtil = new Object;
//添加事件
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
//移除事件
EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.removeEventListener) {
oTarget.removeEventListener(sEventType, fnHandler, false);
} else if (oTarget.detachEvent) {
oTarget.detachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = null;
}
};
//获取event对象
EventUtil.getEvent = function(event) {
return event?event:window.event;
};
//获取事件目标
EventUtil.getTarget = function(event) {
return event.target || event.srcElement;
}
//停止默认事件
EventUtil.preventDefault = function(event){
if(event.preventDefault){
event.preventDefault();
}else{
event.returnValue = false;
}
}