Skip to content

Instantly share code, notes, and snippets.

@cxytomo
Created October 4, 2012 09:17
Show Gist options
  • Save cxytomo/3832464 to your computer and use it in GitHub Desktop.
Save cxytomo/3832464 to your computer and use it in GitHub Desktop.
在a标签上加事件
var dropdown = function(e) {
e = e || window.event;
var targ = e.target || e.srcElement;
if(targ.tagName === "A" && targ.parentNode.parentNode.className === "general"){
var second = targ.parentNode.getElementsByClassName(targ.parentNode.className)[0];
var status = window.getComputedStyle(second,"").getPropertyValue('display');
if(status ==="none") {
second.style.display = "inline-block";
}
}
e.preventDefault();
}
var leave = function(e) {
e = e || window.event;
var targ = e.target || e.srcElement;
if(targ.tagName === "A" && targ.parentNode.parentNode.className === "general"){
var second = targ.parentNode.getElementsByClassName(targ.parentNode.className)[0];
second.style.display = "none";
}
e.preventDefault();
}
var ul = document.getElementsByClassName('general');
ul[0].addEventListener('mouseover', dropdown, false);
ul[0].addEventListener('mouseout',leave,false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment