0

Q1)我正在使用来自 twitter bootstrap 的工具提示。我只是注意到,当使用 ajax 添加内容时它不起作用。经过大量谷歌搜索后,该解决方案似乎在 ajax 请求后触发了工具提示。但就我而言,这是不可能的,因为我依赖于框架的内置 ajax API。还有其他解决方法吗?

$('.tootip').tooltip({placement:'left'});

Q2) 在 jQuery on() 文档中,用法被提及为

$(document).on(event, selector, function(){ //do stuff here })

所以这是我必须做的吗?

$(document).on('ready', '.tootip', tooltip({placement:'left'}));

但它不起作用。

4

1 回答 1

1

A1)您为 ajax 调用提供的选项/参数之一是回调函数,当 ajax 调用完成并成功时触发。这个成功回调应该初始化工具提示。
例如,如果您使用 jQuery:

$.ajax({
    url: 'your url'
    success: function(result) {
        // do your sruff here. Result holds the return data of the ajax call
    }
});

A2) 查看第三个参数:function(){ //do stuff here }. 你必须提供一个功能。相反,您提供的是调用函数的结果tooltip({placement:'left'}),在这种情况下返回一个对象而不是函数。你应该做:

$(document).on('ready', '.tootip', function() {
    $('.tootip').tooltip({placement:'left'}); 
});

关于您的评论的更新:
在函数内部,无论是成功回调还是事件函数,您都可以做任何您喜欢的事情,包括调用多个函数:

$(document).on('ready', '.tootip', function() {
    // Do many operations as much as you like here
    func1();
    func2();
});

$.ajax({
    url: 'your url'
    success: function(result) {
        // Do many operations as much as you like here
        func1();
        func2();
    }
});

希望这可以帮助!

于 2012-11-14T06:46:05.837 回答