q提示为每个更改特定工具提示的文本

qTip change text of specific tooltip after for each

本文关键字:工具提示 文本 提示      更新时间:2023-09-26

我有一个html页面,其中包含一些输入和文本区域。我希望他们有不同文本的qTip。

这是我的尝试首先,我给每个元素添加一个qTip,

$('input, textarea').each(function() {
        $(this).qtip(
                { 
                content : 'generated', //this is for debug
                position : {
                    my : 'center left',
                    at : 'center right',
                    adjust : {
                        x : 90
                    }
                }
            });
});

然后我试图更改一个类似的qTip文本

$("#firstName").qtip('option', 'content.text', 'adwd');

但它不起作用。

我试过这个

$("#lastName").qtip({
    content : 'text text'
});

工作正常,但它覆盖位置

这段代码适用于我:

$("#firstName").qtip('option', 'content.text', 'new tooltip content')

如果你必须在一个事件上更改它(例如over或类似的),请尝试使用以下代码:

// make sure you target a specific tip
var qapi = $('#firstName').data('qtip'),
newtip = 'new tooltip content'
qapi.options.content.text = newtip; // update content stored in options
qapi.elements.content.text(newtip); // update visible tooltip content
qapi.redraw(); // redraw to adjust tooltip borders

代码只更新一个特定选项,其余选项保持原样。

演示:http://jsfiddle.net/IrvinDominin/L7fs5/