Created
October 4, 2012 09:17
-
-
Save cxytomo/3832464 to your computer and use it in GitHub Desktop.
在a标签上加事件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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