繁体   English   中英

jQuery如何从锚中删除id标签

[英]jQuery how to remove id tag from anchor

您好我是jQuery的新手并且正在学习,所以我需要您的帮助来解决我的问题。

我正在使用jQuery ajax,我想在ajax成功后从锚链接中删除id属性。

例如,我有这个链接:

<a id="like_14" href="javascript:void(0);">Link</a>

想要这个

<a href="javascript:void(0);">Link</a>

注意:在ajax成功之后我不想使用id="like_14" 完全从锚链接中删除。

我的Ajax代码是:

$(function () {
        $('.load_more_ctnt .ovrly a').live("click", function () {
            var getImageID = $(this).attr("id");
            if (getImageID) {
                $.ajax({
                    type: "POST",
                    url: "<?php echo URL; ?>home/passImageID",
                    data: "getImageID=" + getImageID,
                    success: function (html) {
                        alert(getImageID);
                    }
                });
            } else {
                 //$(".more_tab").html('The End');
            }
            return false;
        });
    });

我从这个变量获取ID: var getImageID = $(this).attr("id");

任何想法?

谢谢。

你可以使用.removeAttr()

$("#like_14").removeAttr("id");

然后你的代码看起来像

$(function () {
    $('.load_more_ctnt .ovrly a').live("click", function () {
        var getImageID = $(this).attr("id");
        if (getImageID) {
            $.ajax({
                type: "POST",
                url: "<?php echo URL; ?>home/passImageID",
                data: "getImageID=" + getImageID,
                success: function (html) {
                    alert(getImageID);
                    $("#" + getImageID).removeAttr("id");
                }
            });
        } else {
            //$(".more_tab").html('The End');
        }
        return false;
    });
});

在jquery中使用.removeAttr()

$(this).removeAttr("id");

用空格替换id:

$("#like_14").attr("id","");

或删除

$("#like_14").removeAttr("id");
success: function (html) {
                        //alert(getImageID);

                       $('#'+getImageID).removeAttr('id');
                    }

Rerence

暂无
暂无

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

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