你好,我是 jQuery 新手,正在学习,所以我需要你的帮助来解决我的问题。
我正在使用 jQuery ajax,我想在 ajax 成功后从 anchor 链接中删除 id 属性。
例如我有这个链接:
<a id="like_14" href="javascript:void(0);">Link</a>
想要这个
<a href="javascript:void(0);">Link</a>
注意:我不想在 ajax 成功后使用 id="like_14"
。完全从 anchor 链接中删除。
我的 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;
});
});
关于javascript - jQuery 如何从 anchor 中删除 id 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22905598/