jQuery 查询。按属性名称删除元素。如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7631594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:05:29  来源:igfitidea点击:

JQuery. Remove element by attribute name. How?

jquery

提问by suchislife

Is there a way to remove a DIV based on it's custom attribute comment_id?

有没有办法根据它的自定义属性 comment_id 删除 DIV?

I have the following code but it does not quite work yet.

我有以下代码,但它还不能正常工作。

<script type="text/javascript">
    $('.delete_comment').live('click', function() {
        // Url we request data from
        $.get( "http://www.site.com/pages/delete/user_comment.php",
        // Url parameters to send 
        {id:$(this).attr('comment_id'),c:'yes'},
        // Output data from php file generated by PHP echo.
        function(data)
        { 
            var comment_id = $(this).attr('comment_id').val();
            //alert(comment_id);
            if (comment_id == data) {

                $(this).remove();

            }

        });

    });
</script>