首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用html5 data-tip可以在data-tip中添加链接吗?

使用html5 data-tip可以在data-tip中添加链接吗?
EN

Stack Overflow用户
提问于 2014-02-28 04:29:47
回答 1查看 5K关注 0票数 1

是否可以在数据提示内添加可单击的链接,如果可以..它是如何做到的?使用jquery工具提示会更好吗?

http://jsfiddle.net/BumU5/3/

代码语言:javascript
复制
<p data-tip="This is the text of the tooltip">This is a paragraph of text that has a tooltip.</p>

<div data-tip="This is the text of the tooltip2">
    <input type="text" name="test" value="44"/>
</div>

[data-tip] {
    position:relative;

}
[data-tip]:before {
    content:'';
    /* hides the tooltip when not hovered */
    display:none;
    content:'';
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #1a1a1a;   
    position:absolute;
    top:30px;
    left:35px;
    z-index:8;
    font-size:0;
    line-height:0;
    width:0;
    height:0;
}
[data-tip]:after {
    display:none;
    content:attr(data-tip);
    position:absolute;
    top:35px;
    left:0px;
    padding:5px 8px;
    background:#1a1a1a;
    color:#fff;
    z-index:9;
    font-size: 0.75em;
    height:18px;
    line-height:18px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    white-space:nowrap;
    word-wrap:normal;
}
[data-tip]:hover:before,
[data-tip]:hover:after {
    display:block;
}
EN

回答 1

Stack Overflow用户

发布于 2014-02-28 06:20:12

试试这个(更新版)

代码语言:javascript
复制
<!-- html -->
<p id="tooltip" data-tip-link="http://example.com/tool-tip-link" data-tip-text="This is the text of the tooltip">This is a paragraph of text that has a tooltip.</p>

js

代码语言:javascript
复制
$(document).ready(function() {
  $("p#tooltip").hover(
    function() {
      $(this).html("<a href="+$(this).data("tip-link")+">tool tip link</a><br>"
      +$(this).data("tip-text"))
    }, 
    function() {
      $(this).html("This is a paragraph of text that has a tooltip.")
  });
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22079653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档