Javascript 如何在类上但仅在某些元素上使用onclick

Javascript 如何在类上但仅在某些元素上使用onclick,javascript,jquery,html,Javascript,Jquery,Html,这就是我的HTML代码的样子,在实际代码中有几个类似的块。当您单击此DIV中的某个位置时,将调用toogleDescription(此)。我的问题是,我不希望在单击其中一个锚点(a)时发生任何事情,那么是否可以在Javascript中定义某个DIV,使其不会发生任何事情 <div class="dokumente_table"> <div class="dokumente_group onclick="toggleDescription(this)">

这就是我的HTML代码的样子,在实际代码中有几个类似的块。当您单击此DIV中的某个位置时,将调用toogleDescription(此)。我的问题是,我不希望在单击其中一个锚点(a)时发生任何事情,那么是否可以在Javascript中定义某个DIV,使其不会发生任何事情

<div class="dokumente_table">
    <div class="dokumente_group onclick="toggleDescription(this)">
        <img class="dokumente_triangle" src="/_files/img/triangle_13.png">
        <div class="button_group">
            <a class="button">Content...</a>
            <a class="button">Content...</a>
        </div>
        <div class="dokumente_download_frame">
            <a class="dokumente_download">Content...></a>
        </div>
        <div class="dokumente_row">
            Content...
        </div>
        <div class="dokumente_row">
            Content...
        <div class="dokumente_extra_row">
            Content...
        </div>
    </div>
</div>

您需要按如下所述更改此行:

 <div class="dokumente_group onclick="toggleDescription(this,event)">

如果不希望在单击特定锚点时执行
toggleDescription
,可以使用特定锚点的单击事件中的事件对象的
stopPropagation()
方法阻止单击的传播

例如,如果要跳过以下锚的执行

<a class="dokumente_download">Content...></a>
检查此选项,将on('click',函数(e){e.preventDefault()})事件绑定到您不希望在单击时发生任何事情的锚点。
function toggleDescription(that,event) {
    if(!$('a').is(event.target)){
        if($(that).find('.dokumente_extra_row').is(':visible')) {    
            $(that).find('.dokumente_extra_row').slideUp(500);
            $(that).find('.dokumente_triangle').rotate({
                duration: 1000,
                angle: 90,
                animateTo: 0
            });
        }
        else {
            $(that).find('.dokumente_extra_row').slideDown(500);
            $(that).find('.dokumente_triangle').rotate({
                duration: 1000,
                angle: 0,
                animateTo: 90
            });
        }
    }
}
<a class="dokumente_download">Content...></a>
$(".dokumente_download").click(function(e){
 e.stopPropagation();
});