JavaScript 如何去掉链接的下划线
给定一个链接,任务是使用JavaScript去掉锚点元素中的下划线。下面讨论了两种方法:
方法1: 使用JavaScript的 textDecoration属性 来执行此操作。它可以设置为许多值,但在本示例中,设置为 none 。
示例: 此示例展示了上述方法的使用。
<!DOCTYPE html>
<html lang="en">
<head>
<title>
How to remove underline from
link using JavaScript ?
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>
Click on the button to perform
the operation
</p>
<a id="link" href="#">This is Link</a>
<br><br>
<button onclick="GFG_Fun()">
Click Here
</button>
<p id="GFG"></p>
<script>
let elm = document.getElementById('GFG');
function GFG_Fun() {
let linkContent = document.getElementById('link');
linkContent.style.textDecoration = "none";
elm.innerHTML = "Underline Removed";
}
</script>
</body>
</html>
输出:
方法2: 使用JavaScript的 textDecoration属性 来执行操作。在这个示例中,我们将值设置为 line-through 。
示例: 这个示例展示了上面解释的方法的使用。
<!DOCTYPE html>
<html lang="en">
<head>
<title>
How to remove underline from
link using JavaScript ?
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>
Click on the button to perform
the operation
</p>
<a id="link" href="#">This is Link</a>
<br><br>
<button onclick="GFG_Fun()">
Click Here
</button>
<p id="GFG"></p>
<script>
let elm = document.getElementById('GFG');
function GFG_Fun() {
let linkContent = document.getElementById('link');
linkContent.style.textDecoration = "line-through";
elm.innerHTML = "Underline Removed";
}
</script>
</body>
</html>
输出: