jQuery qTip - 创建前触发

时间:2011-09-15 07:27:47

标签: jquery events qtip

我尝试在创建qtip之前触发someFunction()

$('.selector').qtip({
   content: {
      text: someFunction(this.id) }
});

此代码有效,但我认为这是一个肮脏的解决方案。在大多数jquery插件中是否有start: event类似(例如draggable)?我在文档中没有发现它。

编辑:好的,这段代码不行。他在页面加载时触发了该功能而不是onhover。

更新

function someFunction(someId)
{
    // some code ...
    var searchResult = ' ... some results from the search -> from '+someId+' ... ';
    return searchResult;

}

3 个答案:

答案 0 :(得分:3)

您需要传递someFunction,而不是someFunction()。后者调用函数并将返回值赋给text,然后再也不调用该函数。通过传递函数本身,qTip将看到该函数并在必要时调用它。

答案 1 :(得分:1)

使用回拨选项beforeShow :,这是更好的方法。

Reference here.

也可以从someFunction删除括号。

$('.selector').qtip({
    api : {
        beforeShow : function (someId)
        {
            // some code ...
            var searchResult = ' ... some results from the search -> from '+someId+' ... ';
            // place text in tooltip
        }
    }
});

<强> Working Sample.

答案 2 :(得分:0)

在Qtip2中,它已改为jquery style ui events

$('.selector').qtip({
   events: {
      render: function(event, api) { }, // old onRender
      show: function(event, api) {}, // old beforeHide (return false or call event.preventDefault() to stop the show)
      hide: function(event, api) {} // old beforeHide (same as above)
   }
})