我试过了:
<div style="display:block;">
<a href="/go" style="display:block;height:100%;width:100%;position:absolute;"></a>
LOTS OF STUFF HERE
<input type="button" onclick="runsomething();return false;">
</div>
但它不起作用。它确实点击跟随锚...但按钮也跟随锚,我不想要。
编辑:该按钮甚至不会点击。它不会压下来!就像Anchor完全覆盖它一样。
答案 0 :(得分:1)
您可以使事件从按钮上停止传播,因此它永远不会到达DIV。
$(".myDiv input").click(function(e){
e.stopPropagation();
});
有关event.stopPropagation
的详情,请参阅http://api.jquery.com/event.stopPropagation/
由于某种原因,您的锚占用了父容器的整个大小。为什么?这将掩盖您的按钮,可能使其无法访问。我知道你想让整个DIV可以点击,但这是错误的做法。请考虑以下事项:
$(".myDiv").click(function(){
window.location = $("a:first", this).attr("href");
});
这会导致点击此DIV将用户发送到其链接发送它们的任何位置。最好的是你不需要在你的链接或DIV中添加任何CSS。 Javascript将在div中找到该链接,获取其href
值,然后向该用户发送该用户。