2016-01-21 100 views
1

我想添加图像的文字按钮的标题.. 我已经尝试添加图像通过使用下面的PHP代码title =“”。如何在工具提示的标题中添加图像?

<?php echo"<img class='file-attach'  src='".get_template_directory_uri()."/images/file-attachment.png'/>"; ?> 

<button type="button" class="btn btn-default tooltip-buttons" data-toggle="tooltip" data-placement="top" title="Here you'll see">?</button> 
+0

使用本地'提供title'属性,不,你不能这样做。如果您需要支持图片的图片,则必须实施自定义图片。 –

+0

http://stackoverflow.com/questions/15274123/how-do-you-add-an-image-to-a-jquery-tooltip –

+0

请参阅此链接可能会解决您的问题http://stackoverflow.com/questions/15274123 /怎么办 - 你 - 附加的图像对A-jQuery的工具提示 –

回答

1

我实现与图片的工具提示类似以假乱真,这里是代码:

$("[ctitle]").hover(
    function(e) { 
    $("<div id='txt'>").css({ 
     "display": "none", 
     "width": "auto", 
     "height": "auto", 
     "color": "#767676", 
     "border": "solid 1px #767676", 
     "font-size": "12px", 
     "font-family": "Arial", 
     "position": "absolute", 
     "padding": "2px 3px 2px 3px", 
     "background-color": "white", 
     "box-shadow": "3px 3px 1px gray", 
     "left": 0, 
     "top": 0 
    }).appendTo("body").html($(this).attr('ctitle')).stop().fadeToggle().css({ 
     "top": e.pageY, 
     "left": e.pageX 
    }); 

    }, 
    function() { 
    $("[id='txt']").stop().fadeToggle(function(){ 
      $(this).remove(); 
     }) 
    } 
); 

基本上代码添加到您的网页(包括JQuery的),并使用ctitle代替title。在ctitle属性中,您可以添加其他HTML代码进行格式化。

Here is the JSFiddle demo