繁体   English   中英

字体真棒,当我单击字体时,ptoperly无法正常工作

[英]Font awesome as a button, when i click on the font it does not work ptoperly

当我单击“ x”时,它不起作用,仅当我在外部单击时才起作用(id #close的填充为3px)。 我尝试通过将#id分配给i标签来尝试,它甚至没有触发事件。 我该怎么办,以使点击事件关闭时#id内部的所有内容都会触发。

html

 <span id="close"><i class="fa fa-times-circle"></i></span>

js

 $('#close').click(function(event){
        if(event.target.id=='close'){
            $(this).parent().parent().remove();
            $(this).remove();
       }
  });

为什么要使用这种条件?

 if(event.target.id=='close')

我创建了这个JSFiddle,它可以工作: JSFiddle

您的代码无法正常运行,因为event.target.id并非每次都close 这是一个JSFiddle来说明问题。

您要做的只是在#close上处理click事件。 请注意, $(this) 始终是当前选择器:

$("#close").click(function(event) {
    var $topParent = $(this).parent().parent();

    $(this).remove();
    $topParent.remove();
});

暂无
暂无

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

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