问题
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