2013-06-30 11 views
5

Próbuję napisać kod do stronicowania. Jedną z funkcji jest wyłączenie bieżącego łącza tak, aby wyglądało jak tekst i było niemożliwe do skasowania. W stronę html może to być osiągnięte przez pominięcie atrybutu href jak:Usuwanie atrybutu href

<a>Link</a> 

nie mogłem zrobić w JavaScript,

AvdonPagination.prototype.manageLinks = function(link){ 
    if(link){ 
     this.current.href = '#'; 
     this.current = link; 
    }else{ 
     this.current = this.links[0]; 
    } 
    this.current.href = null; 
} 

ponieważ

this.current.href = null; 

produkuje

<a href="null">Link</a> 

Próbowałem także this.current.href="" i this.current.disabled=true, ale żadna z nich nie działa. Jak mogę osiągnąć <a>Link</a>?

+0

widziałeś http://stackoverflow.com/questions/2533406/how-to-disable-a-html-tag –

+1

Czy próbowałeś removeAttribute? https://developer.mozilla.org/en-US/docs/Web/API/element.removeAttribute – zdyn

+1

Aby usunąć atrybut z elementu użyj removeAttribute – Musa

Odpowiedz