您好我是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",success: function (html) { alert(getImageID); $("#" + getImageID).removeAttr("id"); } }); } else { //$(".more_tab").html('The End'); } return false; }); });