Removing the href attribute

只愿长相守 提交于 2020-02-27 20:56:59

问题


I'm trying to write a code for pagination. One function is to disable the current link so it looks like text and to be unclickable. In html page this could be achieved by omitting the href attribute like :

<a>Link</a>

I couldn't do that in javaScript,

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

because

this.current.href = null;

produces

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

Also I tried this.current.href="", and this.current.disabled=true, but neither of them works. How I can achieve <a>Link</a>?


回答1:


try this removeAttribute("href")




回答2:


Try the attached code snippet. It uses javascript and currently removes the link function to the third link. You can easily adapt it by adding more lines in javascript to reflect the lines you want to remove the link (but keep text).

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>

<a id="test-1" href="test-1">test-1</a>
<a id="test-2" href="test-2">test-2</a>
<a id="test-3" href="test-3">test-3</a>

<script>
document.getElementById("test-1").removeAttribute("href");
</script>

</body>
</html>


来源:https://stackoverflow.com/questions/17387357/removing-the-href-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!