javascript - 不能使用嵌套 anchor

标签 javascript jquery html css

好的。我有以下脚本:

$('#exhibitions .item.plain').toggle(
    function() {
        $(this).css({
           'height': '302px',
           'z-index': '10',
           'background': '#3F94AB'
        });
        $(this).find('p.title').css('color', '#E6E6E6');
        $container.isotope('reLayout');
    },
    function() {
        $(this).css({
           'height': "130px", 
           'z-index': '0',
           'background': '#CCC'
    });
    $(this).find('p.title').css('color', '#353334');
    $container.isotope('reLayout');
});

.item.plain 被赋予带有嵌套 anchor 的 div。当我点击它时,很明显 )) toggle() 被触发了。

<div class="item plain">
     <!-- some stuff -->
     <a href="url I want to go"></a>
</div>

我该如何解决这个问题?

谢谢!

最佳答案

如果我很清楚您不想在单击链接时切换元素 .item.plain,那么请停止以这种方式传播事件

$('#exhibitions .item.plain a').on('click', function(evt) {
   evt.stopPropagation();
});

关于javascript - 不能使用嵌套 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10737888/

相关文章:

javascript - 遍历字符串中的单词

javascript - 如何将js类包装到短信中?

html - CSS3 媒体查询未加载

html - Bootstrap 嵌套行和列未正确堆叠

javascript - 通过 Google Chrome 扩展从注入(inject)的 html 调用带有 ng 指令的函数

javascript - if 语句不正确

javascript - Bootstrap Modal和YouTube Player技巧

php - 使用 PHP 和 JQuery 上传多个文件

javascript - 如何让我的 TreeView 元素溢出超过父 div 的宽度?

javascript - 单击使用 JavaScript 时尝试更改单个文本字母