[英]How to remove href attribute from anchor tag after loading or while loading the page by using java script or jquery
我必须禁用链接,以便我尝试从标签中删除 href 属性,以便我使用下面的代码,但 dom 在显示错误时没有得到。 请帮助我克服错误。
var a = document.querySelector('.link');
a.removeattribute('href');
显示错误:removeAttribute() 的 null。
jquery 中的建议也很好。
以下是我的评论的一个工作示例。
(() => { document.querySelectorAll('a').forEach(a => { a.addEventListener('click', () => { a.removeAttribute('href'); }, true); }); })();
a:not([href]) { color: rgb(255, 80, 80); } a { color: blue; }
<a href="#loading">Load that page</a> <a href="#">Or that page</a> <a href="#">Perhaps even that other page</a>
纯javascript版本:
var a = document.querySelector('.link');
a.removeAttribute('href');
jQuery版本:
$('.link').removeAttr('href');
注意: removeAttribute
与removeattribute
不同,所以当您决定使用 js 版本时,请确保您输入正确的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.