2013-06-30 157 views
5

我正在尝试编写分页代码。一个功能是禁用当前链接,使其看起来像文本并且不可点击。在HTML页面,这可以通过省略href属性等来实现:删除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>

+0

你见过http://stackoverflow.com/questions/2533406/how-to-disable-a-html-tag –

+1

您是否尝试过的removeAttribute? https://developer.mozilla.org/en-US/docs/Web/API/element.removeAttribute – zdyn

+1

要从元素中删除属性,请使用removeAttribute – Musa

回答