【问题标题】:Removing the href attribute删除 href 属性
【发布时间】: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,但它们都不起作用。 我怎样才能达到&lt;a&gt;Link&lt;/a&gt;?

【问题讨论】:

标签: javascript hyperlink href


【解决方案1】:

【讨论】:

【解决方案2】:

试试附带的代码 sn-p。 它使用 javascript,目前删除了第三个链接的链接功能。 您可以通过在 javascript 中添加更多行来轻松调整它,以反映您要删除链接的行(但保留文本)。

<!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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-04
    • 2012-09-13
    • 1970-01-01
    • 2015-05-09
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    相关资源
    最近更新 更多