删除 href 属性并添加操作 = "1004"



我有上下文菜单,右键单击链接时,我使用以下代码获取了它的 HTML:

thisDiv = target_element.parent().html();

console.log(thisDiv)是:

<a href="http://goo.com" class="sim-row-edit" data-type="link">goo</a>

如何删除属性href并添加属性action="1004"

使用removeAttrjquery 函数进行删除。

target_element.parent().removeAttr('href');

对于添加属性功能。

target_element.parent().attr('action', '1004');
$(".sim-row-edit").removeAttr("href").attr("action","1004");

只需使用 removeAttr("href"( 删除 href 属性,然后添加新属性 attr("action","1004"(。

selector.removeAttr("href"(.attr("action","1004"(;

最新更新