简体   繁体   English

jQuery UI工具提示-动态内容

[英]jQuery UI tooltip - dynamic content

I want to change the contents of the tooltip as I drag the div that has the tooltip. 我要在拖动具有工具提示的div时更改工具提示的内容。 I would like to show the ui.position.top in the tooltip using the drag event for the div. 我想使用div的drag事件在工具提示中显示ui.position.top。 Is this possible? 这可能吗? I know the jQuery UI API docs regarding tooltip content says: 我知道有关工具提示内容的jQuery UI API文档说:

When changing this option, you likely need to also change the items option. 更改此选项时,您可能还需要更改项目选项。

but I cannot figure out how to do this correctly. 但我不知道如何正确执行此操作。

This is what I have: 这就是我所拥有的:

HTML HTML

<div id="box" title="original">drag me</div>

JS JS

$("#box").tooltip({
    track: true
});
$("#box").draggable({
    drag: function(event,ui){
        $(this).tooltip("option", "content", ui.position.top);
    }
});

http://jsfiddle.net/E9vf3/8/ http://jsfiddle.net/E9vf3/8/

As detailed in the API you can get or set the content option, after initialization. API中所述,您可以在初始化后获取或设置content选项。 Your latest amend to your question is almost right but the tooltip is expecting a string as the final value. 您对问题的最新修正几乎是正确的,但tooltip期望将字符串作为最终值。

$("#box").tooltip({
    track: true
});
$("#box").draggable({
    drag: function(event,ui){
        $(this).tooltip( "option", "content", ""+ui.position.top );
    }
});

http://jsfiddle.net/E9vf3/10/ http://jsfiddle.net/E9vf3/10/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM