首页 > 解决方案 > 显示 Hover 而不是 Href 进行条件检查

问题描述

我有一个非常基本的 html 要求,在某些参数值上,我需要隐藏文本上的超链接并在文本上显示悬停。

下面是我的测试html。当访问码=10时,我应该如何处理我的Javascript,我应该只显示悬停而不是href?

<!DOCTYPE html>
<html>

<body>
<h1>test Heading</h1>
<p>Test screen.</p>

 <a id="tagUrl" class="button" href='https://growthModeltest.com' target="_blank" rel="MonthlyReport">Learn More</a>

</body>
<script>
var accessCode= 10;
var hideElem = document.getElementById("tagUrl");
if(accessCode == 10){
        //should not display the link, instead show the hover.
        hideElem.href = '#';
}

</script>
</html>

标签: javascripthtmlinternet-explorer

解决方案


如果您想创建一个在您将鼠标悬停在链接上时显示的工具提示,请分配该title属性。

var accessCode = 10;
var hideElem = document.getElementById("tagUrl");
if (accessCode == 10) {
  //should not display the link, instead show the hover.
  hideElem.href = '#';
  hideElem.title = 'Link is not active now';
}
<h1>test Heading</h1>
<p>Test screen.</p>

<a id="tagUrl" class="button" href='https://growthModeltest.com' target="_blank" rel="MonthlyReport">Learn More</a>


推荐阅读