【发布时间】:2013-06-27 13:32:09
【问题描述】:
我正在尝试编写分页代码。一种功能是禁用当前链接,使其看起来像文本并且不可点击。在 html 页面中,这可以通过省略 href 属性来实现,例如:
<a>Link</a>
我无法在 javaScript 中做到这一点,
AvdonPagination.prototype.manageLinks = function(link){
if(link){
this.current.href = '#';
this.current = link;
}else{
this.current = this.links[0];
}
this.current.href = null;
}
因为
this.current.href = null;
生产
<a href="null">Link</a>
我也试过this.current.href=""和this.current.disabled=true,但它们都不起作用。
我怎样才能达到<a>Link</a>?
【问题讨论】:
-
你试过removeAttribute吗? developer.mozilla.org/en-US/docs/Web/API/…
-
要从元素中删除属性,请使用 removeAttribute
-
@J Max 是的,但这无济于事。正如我所描述的,我不想阻止链接的默认操作,也不想让它“显示:'none'”,我正在寻找其他东西。
-
@zdyn,@Musa,谢谢。 removeAttribute 正是我需要的。
标签: javascript hyperlink href