Qualtrics问卷中实现点击触发Tooltip而非hover的简便方法
实现点击触发提示框的简便方案(Qualtrics问卷场景)
你当前使用HTML原生title属性实现hover触发提示,要改成点击触发且无需大量额外代码,有两个简便可行的方案:
方案1:使用原生<details>/<summary>标签(零额外代码)
这是HTML原生支持的折叠/展开组件,完全不需要CSS或JS,直接嵌入Qualtrics即可实现点击显示/隐藏提示文本的效果:
<i>Please complete the following sentences related to how other factors impact the <details> <summary><b>risk of negative societal effects from climate change and SG deployment (if any) in 2050 and in 2100.</b></summary> Text describing this concept </details> </i>
点击加粗的目标文本(<summary>内的内容)就会展开显示提示文本,再次点击则收起,兼容性好且无需额外配置。
方案2:极简内嵌JS实现类Tooltip效果
如果想要更贴近原hover提示框的悬浮样式,可通过一行内嵌JS实现点击触发提示,无需额外CSS文件:
<i>Please complete the following sentences related to how other factors impact the <span onclick="this.title = this.dataset.title; setTimeout(() => delete this.title, 3000)" data-title="Text describing this concept"> <b>risk of negative societal effects from climate change and SG deployment (if any) in 2050 and in 2100.</b> </span> </i>
- 点击目标文本时,会将
data-title中存储的提示内容赋值给title属性,触发原生Tooltip显示 - 3秒后自动清除
title属性,提示框消失;也可修改逻辑为再次点击时清除,比如把setTimeout替换为this.title ? delete this.title : this.title = this.dataset.title
内容的提问来源于stack exchange,提问作者daler6
相关产品推荐
相关产品推荐

