在div中锚定标签。当div单击它时,页面应该重定向到一个页面,如果锚点单击页面应该重定向到另一个页面 [英] anchor tag inside a div. When div click it page should redirect to one page and if anchor click the page should redirect to another page

查看:177
本文介绍了在div中锚定标签。当div单击它时,页面应该重定向到一个页面,如果锚点单击页面应该重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div onclick =page reddirec to one 

位置style =height:200px; width:200px>< a href =http://www.google.com>文字< / a>< / div>

这里的div的高度和宽度都是200px,并且点击页面应该重定向到一个位置的div。但是在这个div里面也有一个锚标签,但是点击这个锚标签页应该重定向到另一个位置。是否有可能通过html或使用javascript来实现此功能。

解决方案

您可以试试这个。

$ b ($($)$ $ $ $ $ $ $ $ $ $ $ $'$'$''$' )){
//这将停止事件冒泡并打开锚点的$ h
e.stopPropagation();
}
else {
location.href =anotherUrl;
}
});


I have an one div inside that an anchor tag like this.

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

Here div having height and width 200px each and also onclick the div the page should redirect to one location. But also there is an anchor tag inside this div but onclick this anchor tag the page should redirect to another location. Is it possible to implement this in html or by using the javascript.

解决方案

You can try this.

$('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";
    }
});

这篇关于在div中锚定标签。当div单击它时,页面应该重定向到一个页面,如果锚点单击页面应该重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆