Javascript jQuery:div元素链接内的其他链接
如果所有图标仍在div元素中,如何进行分离 基本上,在div中,我有4个东西要点击。最后一个是链接整个div元素click。中间的元素用于特定的图标单击。但是现在,对于特定的图标点击,我希望点击连接到他们自己的链接。例如,如果单击github png,它应该转到github链接,但现在google div链接会覆盖它。无论我点击什么,我只连接到一个链接,我并不打算这样做 谢谢Javascript jQuery:div元素链接内的其他链接,javascript,jquery,css,html,Javascript,Jquery,Css,Html,如果所有图标仍在div元素中,如何进行分离 基本上,在div中,我有4个东西要点击。最后一个是链接整个div元素click。中间的元素用于特定的图标单击。但是现在,对于特定的图标点击,我希望点击连接到他们自己的链接。例如,如果单击github png,它应该转到github链接,但现在google div链接会覆盖它。无论我点击什么,我只连接到一个链接,我并不打算这样做 谢谢 <script type="text/javascript"> $(document).ready(
<script type="text/javascript">
$(document).ready(function(){
$(".Apps").click(function(){
window.open($(this).find("a").last().attr("href"));
return false;
});
});
</script>
<div class="Apps">
<p><b>Web Dev Project 3</b><br><i>(coming soon)</i></p>
<a href="https://github.com/" target="blank">
<img src="https://github.com/apple-touch-icon-114.png" width="30" height="30"/></a>
<a href="http://google.com" target="blank">
<img id="logo" src="http://cclub.slc.engr.wisc.edu/images/Under-Construction.gif" width="30" height="30"/></a>
<a href="http://google.com" target="blank"></a>
</div>
$(文档).ready(函数(){
$(“.Apps”)。单击(函数(){
window.open($(this.find(“a”).last().attr(“href”));
返回false;
});
});
Web开发项目3
(即将推出)
实际上没有这样的概念,即
与包含元素“连接”。与此相反,为什么不捕获
上的“单击”事件并过滤掉图标上没有的事件:
$('div.Apps').on("click", ":not(a img)", function() {
window.location = "http://google.com";
});
按照标记的方式,很难说在容器中会有一个不是图标的屏幕区域,但可能有填充/边距或其他内容。排除锚定:
$(".Apps").click(function(e){
if (! $(e.target).closest('a').length ) {
window.open($(this).find("a").last().attr("href"));
return false;
}
});
如果我是你,我会为div和a链接分配不同的id,然后在a特定的链接指令中只阻止默认的点击行为
$(´#aLinkId´).on(´click´, function(){
event.preventDefault();
event.stopPropagation();
window.open(whatever here);
});
$(´#aDivId´).on(´click´, function(){
window.open(other whatever here);
});
我知道你在找什么吗
你能把你的问题说清楚一点吗。你在说什么链接?在图标上设置更高的
z-index
。@RobertKeenan你的空
标记在屏幕上不占空间,因此无法单击它。
$(document).ready(function () {
$(".Apps").click(function () {
window.open($(this).find("a").last().attr("href"));
return false;
});
$(".Apps > a").click(function () {
window.open($(this).attr("href"));
return false;
});
});