以编程方式重新加载 Ajax 选项卡内容时出现问题?

发布于 2024-11-28 19:41:44 字数 496 浏览 0 评论 0原文

如何在运行时动态设置 jQuery 的 ajax 选项卡的 url?

这样做:

$(function() {
    //$("#tabs").tabs();
    $("#tabs").tabs("url" , 0, "dep.php" );
});

html

<div class="flts">
    <div id="tabs">
        <ul>
            <li><a href="dep.php">Вылеты</a></li>
            <li><a href="arr.php">Посадка</a></li>
        </ul>
    </div>
</div>

但它不起作用!可能有什么问题?

How can I set jQuery's ajax tab's url dynamically in runtime?

Doing like this:

$(function() {
    //$("#tabs").tabs();
    $("#tabs").tabs("url" , 0, "dep.php" );
});

html

<div class="flts">
    <div id="tabs">
        <ul>
            <li><a href="dep.php">Вылеты</a></li>
            <li><a href="arr.php">Посадка</a></li>
        </ul>
    </div>
</div>

but it's not working! What could be a problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮色兮凉城 2024-12-05 19:41:44

你的做法似乎不正确。 $("#tabs").tabs("url" , 0, "dep.php") 的调用被包装在 $(function() { 中,因此它仅在页面第一次加载时运行,这是没有意义的。

正确的方法是:

  • 页面应该只包含带有有效链接的选项卡标签 。选项卡内容。

  • 首次加载页面时,调用$("#tabs").tabs(); 初始化并配置选项卡小部件。< /p>

现在可以使用选项卡小部件并加载选项卡内容 。当第一次显示特定选项卡时(延迟加载)

  • 如果您想稍后刷新或替换选项卡(例如,从事件处理程序),请调用 $("#tabs").tabs("url" , 0, "dep.php")< /code>

因此,整体解决方案可能如下所示:

<div class="flts">
  <div id="tabs">
    <ul>
      <li><a href="dep.php">Вылеты</a></li>
      <li><a href="arr.php">Посадка</a></li>
      </ul>
    </div>
</div>

$(function() {
    // intial tabs configuration
    $("#tabs").tabs();
    // event handler setup for refresh

    $('#refreshButton').click(function() {
      $("#tabs").tabs("url", 0, "dep.php?var=val&var2=val");
    });
});

Your approach doesn't seem correct. The call of $("#tabs").tabs("url" , 0, "dep.php") is wrapped in $(function() {, so it's run only the first time the page is loaded. That makes no sense. This method is used to later replace the tab content.

The correct is approach is:

  • The page should only contain the tab label with a valid link but no tab content.

  • When the page is first loaded, call $("#tabs").tabs(); to intialize and configure the tab widget.

The tab widget is now usable and the tab content is loaded when the specific tab is displayed for the first time (lazy loading).

  • If you want to refresh or replace a tab later (e.g. from an event handler), call $("#tabs").tabs("url" , 0, "dep.php").

So the overall solution could look like this:

<div class="flts">
  <div id="tabs">
    <ul>
      <li><a href="dep.php">Вылеты</a></li>
      <li><a href="arr.php">Посадка</a></li>
      </ul>
    </div>
</div>

$(function() {
    // intial tabs configuration
    $("#tabs").tabs();
    // event handler setup for refresh

    $('#refreshButton').click(function() {
      $("#tabs").tabs("url", 0, "dep.php?var=val&var2=val");
    });
});
扮仙女 2024-12-05 19:41:44

看来您正在尝试使用 AJAX 模式。如果是这种情况,那么您需要指定 ajaxOptions。 此页面有一个简单的示例,应该可以让您明白。

It looks like you're trying to do the AJAX mode. If that be the case, then you need to specify the ajaxOptions. This page has a simple example which should set you straight.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文