页面有多个div 切每个div套有超链接 如:
<div class="a"><a href="a.html"></a></div>
<div class="a"><a href="b.html"></a></div>
<div class="a"><a href="c.html"></a></div>
<div class="a"><a href="d.html"></a></div>
如何让页面加载时默认执行第一个DIV的超链接事件 默认页面加载后就跳到a.html
JS和JQUERY都可以 急急急~
<div class="a"><a href="a.html"></a></div>
<div class="a"><a href="b.html"></a></div>
<div class="a"><a href="c.html"></a></div>
<div class="a"><a href="d.html"></a></div>
如何让页面加载时默认执行第一个DIV的超链接事件 默认页面加载后就跳到a.html
JS和JQUERY都可以 急急急~
$(".a").click();
});自己用JQUERY这样写 但没有跳转
$(document).ready(function () {
location.href = $(".a").attr("href");
});
location.href = $(".a")[0].href;
});
location.href = $(".a:eq(0) a")[0].href;
});
你不就是要问怎么跳转么?
哦,是不是因为我没写
本例中,文本 "Page is loaded" 会被显示在状态栏中:<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "a.htm";
}
</script>
</head><body onload="load()">
</body></html>
window.location.href=$(".a:eq(0) a").attr("href");
});
$('div.a').first().find('a').trigger('click');
var evt = event || window.event;
var target = evt.target || evt.srcElement;
window.location = target.id+".html";
}
/*
@linkId : 不需要跳转的 A 元素 ID
*/
function setLinks(linkId){
var menus = document.getElementById("menus").getElementsByTagName("a");
for(var i=0; i< menus.length; i++){
if(menus[i].id.toLowerCase() != linkId.toLowerCase()){
if (window.attachEvent){
menus[i].attachEvent('click',e)
}else if(window.addEventListener){
menus[i].addEventListener('click',e,false)
}
}
}
}
window.onload = function(){
setLinks('a1');
}
<div id="menus">
<a ID=a1 href="#"> 菜单1</a>
<a ID=a2 href="#"> 菜单2</a>
<a ID=a3 href="#"> 菜单3</a>
<a ID=a4 href="#"> 菜单4</a>
</div>
给 a 标签加上 ID或class 然后
location.href = $("#id名").attr("href");或
location.href = $(".class名").attr("href");调用点击事件只能是a标签的链接 调用外围的DIV不起作用的
谢谢大家 分都给大家