<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自动触发点击超链接</title>
</head>
<body>
<a href="#" id="targ">百度</a>
</body>
<script type="text/javascript">
document.onkeydown = function(event){
var e = event || window.event || arguments.callee.caller.arguments[0]
if(e&&e.keyCode==13){
// IE
if(document.all) {
document.getElementById("targ").click()
}
// 其它浏览器
else {
var ce = document.createEvent('HTMLEvents')
ce.initEvent("click",true,true)
document.getElementById("targ").dispatchEvent(ce)
}
}
}
</script>
</html>
用jquery做的话,代码如下:<title></title>
<script src="../js/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".logo").mouseenter(function () {
$(".logo_pass").css("display", "block")
}).mouseout(function () {
$(".logo_pass").css("display", "none")
})
})
</script>
</head>
<body>
<div class="logo">111</div>
<div class="logo_pass" style="display:none">222</div>
</body>
</html>
js的话:
给div设置id比较好做
<script type="text/javascript">
window.onload = function () {
var logo = document.getElementById("logo")
logo.onmouseover = function () {
document.getElementById("logo_pass").setAttribute("style", "display:block")
}
logo.onmouseout = function () {
document.getElementById("logo_pass").setAttribute("style", "display:none")
}
}
</script>
</head>
<body>
<div id="logo">111</div>
<div id="logo_pass" style="display:none">222</div>
</body>