简体   繁体   English

jQuery可点击div与内部工作mailto链接

[英]jQuery clickable div with working mailto link inside

I have a div that I want to be clickable but I need a mailto link inside that div to still work too. 我有一个div,我想要点击,但我需要在div内部的mailto链接仍然可以工作。 When I hover over the mailto link the mailto appears at the bottom of the browser but clicking activates the link attached to the div. 当我将鼠标悬停在mailto链接上时,mailto会出现在浏览器的底部,但是单击会激活附加到div的链接。 Anyway around this? 无论如何围绕这个? Thanks. 谢谢。

<div class="directory_search_results">
<img src="images/no_photo.png" />   
<ul class="staff_details">
<li class="search_results_name"><a href="http://www.netflix.com">Micheal Staff</a></li>
<li class="search_results_location">University of Illinois</li>
<li class="search_results_email"><a href="mailto:test@test.org">test@test.com</a></li>
    <li class="search_results_phone">(407) 555-1212</li>
    <li class="search_results_office">(407) 555-1212</li>
</ul></div>

And now the jQuery 现在是jQuery

$(document).ready(function(){       
$(".directory_search_results").click(function(){
         window.location=$(this).find("a:first-child").attr("href");
         return false;
});

Add a class to your mailto: link like this: 在mailto中添加一个类:链接如下:

<div class="directory_search_results">
<img src="images/no_photo.png" />   
<ul class="staff_details">
<li class="search_results_name"><a href="http://www.netflix.com">Micheal Staff</a></li>
<li class="search_results_location">University of Illinois</li>
<li class="search_results_email"><a class="nobubble" href="mailto:test@test.org">test@test.com</a></li>
    <li class="search_results_phone">(407) 555-1212</li>
    <li class="search_results_office">(407) 555-1212</li>
</ul></div>

And add following jQuery code 并添加以下jQuery代码

$('.nobubble').click(function(event){
    event.stopImmediatePropagation();
});

This will prevent bubbling of the event up to the parent div ant triggering of a click there. 这将防止事件冒泡到父div触发点击那里。

Consider this. 考虑一下。

one of the items that jquery offers is the modal dialog. jquery提供的项目之一是模态对话框。

Basically it provides a dialog box with a "screen" that sits over the rest of the screen to keep you from clicking on anything else on the page while the dialog is up. 基本上它提供了一个带有“屏幕”的对话框,该屏幕位于屏幕的其余部分,以防止您在对话框启动时单击页面上的任何其他内容。

the div... being a container element can hold multiple items... any item that is inside the div is still considered a part of the div. div ...作为一个容器元素可以容纳多个项目... div中的任何项目仍然被认为是div的一部分。

Now I'm not a pro when it comes to DOM structure and hierarchy, but it sounds to me like what your trying to do will not work. 现在,当谈到DOM结构和层次结构时,我不是专业人士,但听起来像你尝试做的事情是行不通的。

if there is something like a link inside of a div, and jquery is looking at the click event of that element. 如果在div中有类似链接的东西,jquery正在查看该元素的click事件。 I would assume that anything inside the div would be "under" the screen provided by the div. 我会假设div中的任何内容都会在div提供的屏幕下“。 so if you have a link inside a div and you click the link, your also technichally clicking on the div as well. 因此,如果您在div中有链接并且单击该链接,那么您也可以技术性地单击该div。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM