如何从ajax加载的JQuery ui选项卡中获取此方法

How can i get this method from JQuery ui tab which is loaded by ajax

本文关键字:选项 获取 此方法 ui JQuery ajax 加载      更新时间:2023-09-26

我使用jquery ui标签来加载一个html,在这个html中我有一个方法。

$("#tabs").tabs({               
                beforeLoad: function (event, ui) {
                    ui.jqXHR.error(function () {
                        ui.panel.html(
                          "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                          "If this wouldn't be a demo.");
                    });
                    ui.jqXHR.success(function () {
                        alertMe()
                    });
                }
            });
<div id="tabs" style="height: 100%">
        <ul>
            <li><a href="Map.html">Tab 1</a></li>
        </ul>
 </div>

在map.html中我有alertMe方法。这里显示alertMe是未定义的

jqXHR 'success'在服务器成功返回响应时调用,但在任何选项卡呈现逻辑发生之前(例如向页面添加html/js)。因此,更好的解决方案是使用选项卡控件的load方法来处理调用:

$('tab's).tabs({
    beforeLoad: ...
    load: function() {
       alertMe(); // Global JS on loaded fragment will be available on page now
    }
});

API文档:http://api.jqueryui.com/tabs/#event-load