javascript - 显示 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>
解决方案
如果您想创建一个在您将鼠标悬停在链接上时显示的工具提示,请分配该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>
推荐阅读
- assembly - LNK1190:找到无效的修正,类型 0x0001
- php - 获取从一页到另一页的 ID
- java - 命名查询返回 java.sql.Timestamp 而不是 java.util.Date
- java - 单击按钮时出现 IllegalStateException
- vue.js - 动态导入范围 SCSS
- logstash - Logstash 将非结构化日志行合并到一个事件
- android - 使用 mlKit 检测印地语文本
- javascript - 扩展运算符在 Express.js 中的方法映射中不起作用
- java - 如何在kotlin中将arraylist与嵌套arraylist进行比较?
- lua - 为什么我不断收到错误消息“尝试在我的脚本中使用 'Cash' 索引 nil?