0

我的结构是:

<p>
        <span>
            <input type="text" class="key" value="21">
        </span>
        <span>   
            <input type="text" class="value" value="55">

        </span>
        <span>    
            <a href="#" class="updateAction" data-setting-id="1">update</a>
            <a href="#" class="deleteAction" data-setting-id="1">delete</a>
        </span>
    </p>

每当单击删除链接时,我都会尝试像这样删除父元素:

 $(this).parent().parent().hide();
 $(this).closest('p').hide();
4

2 回答 2

2

关闭输入标签并调用preventDefault,它将起作用。

http://jsfiddle.net/P3tEw/

$(document).on("click", ".deleteAction", function (e) {
    e.preventDefault();
    $(this).closest('p').hide();
});
于 2013-05-09T16:03:18.813 回答
1

尝试

$(".deleteAction").click(function(e){

    e.preventDefault();

    var $this = $(this);

    $this.closest('p').fadeOut('slow',function(){
        $(this).remove();
   }); // with a fadeOut effect

});

检查 jsFiddle

于 2013-05-09T16:04:32.917 回答