2

このようなアンカータグの中に1つのdivがあります。

<div onclick="page reddirec to one location"  style="height:200px;width:200px"><a href="http://www.google.com" >text</a></div>

ここでは、高さと幅がそれぞれ 200px の div と、ページを 1 つの場所にリダイレクトする必要がある div をクリックします。ただし、この div 内にはアンカー タグもありますが、このアンカー タグをクリックすると、ページは別の場所にリダイレクトされます。これをhtmlまたはjavascriptを使用して実装することは可能ですか?

4

2 に答える 2

3

これを試すことができます。

$('div').click(function(e){
    if($(e.target).is('a')){
        //this will stop event bubbling and will open the href of the anchor
        e.stopPropagation();
    }
    else{
        location.href = "anotherUrl";
    }
});
于 2012-04-24T19:43:33.340 に答える
0

これは、IE 9、Firefox 11、および Google Chrome 18 で機能します。

<div onclick="window.location='http://www.yahoo.com'" style="height:200px;width:200px;background-color:Red;">
  <a href="http://www.google.com" >text</a>
</div>
于 2012-04-24T19:46:26.390 に答える