如何将HTML添加到jQuery工具提示?

时间:2011-11-04 14:45:00

标签: jquery jquery-tools

我正在尝试在我的页面上设置工具提示。列表中有7个链接都有工具提示。其中6个只使用基本设置,但其中一个需要使用较大的背景图像并具有自定义HTML。当我尝试配置这个时,6个基本工具提示可以正常工作,但是对于1个较大的HTML工具提示没有任何反应。

这是我的代码:

    <tr><td>
    <a class="text_link" title="Tooltip text">Dental Insurance Providers</a>
</td></tr>
<tr><td>
    <a class="text_link" id="health_insurance_tooltip" >Health Insurance Providers</a>
    <div class="tooltip">           
        <a href="#">This is my html tooltip</a>
    </div>
</td></tr>

<script type="text/javascript">
    // initialize tooltip
    $("[title]").tooltip({ 
        position: "top left", 
        effect: 'slide',
        opacity: 1,
        offset: [15, 190],
        tipClass: 'small_tooltip'
        });

     $("#health_insurance_tooltip").tooltip({ 
        position: "top left", 
        effect: 'slide',
        opacity: 1,
        offset: [15, 190]
        });
</script>

<style type="text/css">
/* tooltip styling  */
.small_tooltip {
    display:none;
    background:url(/fcapps/images/tooltip/white_arrow.jpg);
    font-size:12px;
    height:70px;
    width:160px;
    padding:25px;
    color:#255E0D;  
    opacity:1 !important;
    }

.tooltip {
    display:none;
    background:url(/fcapps/images/tooltip/white_arrow_big.png);
    font-size:12px;
    height:70px;
    width:160px;
    padding:25px;
    color:#255E0D;  
    opacity:1;
}
</style>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

尝试在标题标记中嵌入html,而不是将其作为独立的div。这有点不方便,因为你必须逃避HTML中出现的任何引号,但它对我有用。所以替换:

<a class="text_link" id="health_insurance_tooltip" >Health Insurance Providers</a>
<div class="tooltip">           
    <a href="#">This is my html tooltip</a>
</div>

使用:

<a class="text_link" id="health_insurance_tooltip"
    title="This is my <i>html</i> tooltip">Health Insurance Providers</a>
相关问题