javascript 关于 jquery 中动态创建内容的工具提示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22440725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:09:43  来源:igfitidea点击:

tooltip on dynamic created content in jquery

javascriptjqueryhtmltooltip

提问by Michael

How to trigger the tooltip from a content has just created dynamically from jquery?

如何从刚刚从 jquery 动态创建的内容触发工具提示?

I use append function to append a "p"element into a content and with title attribute as well.

我使用 append 函数将"p"元素附加到内容中,并且还具有标题属性。

Every time I need to hover twice on the a newly created element then the tooltipbox will appear. Otherwise hovering on the element first time will show nothing always.

每次我需要在新创建的元素上悬停两次时,tooltip都会出现该框。否则第一次悬停在元素上将始终不显示任何内容。

This is my tooltipfunction. Or maybe I can get the class name and do the matching somehow. Please do guide me.

这是我的tooltip职能。或者也许我可以获取类名并以某种方式进行匹配。请指导我。

$(".tooltip_class").tooltip({
    show: null,
    position: {
        my: "left top",
        at: "left bottom"
    },
    open: function( event, ui ) {
        ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" );
    }
}); 

回答by Foreever

You do not need to put the content as title attribute value. Instead the content can be added in jQuery as follows:

您不需要将内容作为标题属性值。相反,可以在 jQuery 中添加内容,如下所示:

Javascript

Javascript

$( document ).tooltip();
$('#selector').tooltip( "option", "content", "TOOLTIP CONTENT" );

HTML

HTML

<span class="help">
 <a id="selector" title="">  
    What's this?
</a>
</span>

See Demo

演示

回答by king_pintu

$( document ).tooltip(); $('#selector').tooltip( "option", "content", "TOOLTIP CONTENT" );

$( 文档 ).tooltip(); $('#selector').tooltip( "option", "content", "TOOLTIP CONTENT" );