使用html5 data-tip可以在数据提示中添加一个链接吗?

时间:2014-02-27 20:29:47

标签: jquery html5 datatip

是否可以在数据提示中添加可点击的链接,如果是这样的话......怎么做?我会更好地使用jquery工具提示吗?

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

<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;
}

1 个答案:

答案 0 :(得分:1)

试试这个(更新版本)

<!-- 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

$(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.")
  });
})