嵌套 jQuery 选项卡

发布于 2024-08-09 11:28:51 字数 3677 浏览 4 评论 0原文

我是 jQuery 新手(几周)。我正在尝试嵌套 jQueryUI 选项卡控件。它工作正常,直到嵌套选项卡位于外部 文件,然后我在 jQuery 源中抛出异常。这似乎 在某种程度上是一个时间问题,因为如果我发出警报 其工作的嵌套选项卡的 .ready 函数中的框。任何人都可以 帮助?我确信这个问题之前一定有人问过,但之后 几个小时的搜索我似乎找不到解决方案。

这是我非常简单的示例...

外部选项卡

    <head id="Head1" runat="server">
    <title></title>
    <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
      rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
    jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
       ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
       ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#OuterTab").tabs();
        });
    </script>
    </head>
<body>
  <div id="OuterTab">
    <ul>
      <li><a href="innerTab1.aspx" title="InnerTab1"><span>InnerTab1</
         span></a></li>
      <li><a href="innerTab2.aspx" title="InnerTab2"><span>InnerTab2</
         span></a></li>
    </ul>
    <div id="InnerTab1">
    </div>
    <div id="InnerTab2">
    </div>
  </div>
</body>
</html>

InnerTab1.aspx

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
      rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
      jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
      ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
      ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>
   <div id="tabs">
        <ul>
          <li><a href="#tabA1"><span>InnerTabA1</span></a></li>
          <li><a href="#tabA2"><span>InnerTabA2</span></a></li>
        </ul>
        <div id="tabA1"></div>
        <div id="tabA2"></div>
   </div>
</body>
</html>

InnerTab2.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
     <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>
   <div id="tabs">
        <ul>
          <li><a href="#tabB1"><span>InnerTabB1</span></a></li>
          <li><a href="#tabB2"><span>InnerTabB2</span></a></li>
        </ul>
        <div id="tabB1"></div>
        <div id="tabB2"></div>
   </div>
</body>
</html>

提前致谢!

阿德里安

I'm new to jQuery (a couple of weeks). I'm trying to nest the jQueryUI
tab control. It works fine until the nested tabs are in an external
file then I get an exception thrown in the jQuery source. This seems
to be a timing issue to a certain extent, because if I place alert
boxes in the .ready function of the nested tabs it works. Can anyone
help? I'm sure this question must have been asked before, but after
hours of searching I can't seem to find a solution.

Here's my very simple example...

Outer Tab

    <head id="Head1" runat="server">
    <title></title>
    <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
      rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
    jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
       ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
       ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#OuterTab").tabs();
        });
    </script>
    </head>
<body>
  <div id="OuterTab">
    <ul>
      <li><a href="innerTab1.aspx" title="InnerTab1"><span>InnerTab1</
         span></a></li>
      <li><a href="innerTab2.aspx" title="InnerTab2"><span>InnerTab2</
         span></a></li>
    </ul>
    <div id="InnerTab1">
    </div>
    <div id="InnerTab2">
    </div>
  </div>
</body>
</html>

InnerTab1.aspx

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
      rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
      jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
      ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
      ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>
   <div id="tabs">
        <ul>
          <li><a href="#tabA1"><span>InnerTabA1</span></a></li>
          <li><a href="#tabA2"><span>InnerTabA2</span></a></li>
        </ul>
        <div id="tabA1"></div>
        <div id="tabA2"></div>
   </div>
</body>
</html>

InnerTab2.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
     <link type="text/css" href="css/jquery-ui-1.7.2.custom.css"
rel="stylesheet" />
    <script type="text/javascript" src="http://jqueryui.com/latest/
jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/
ui.tabs.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>
   <div id="tabs">
        <ul>
          <li><a href="#tabB1"><span>InnerTabB1</span></a></li>
          <li><a href="#tabB2"><span>InnerTabB2</span></a></li>
        </ul>
        <div id="tabB1"></div>
        <div id="tabB2"></div>
   </div>
</body>
</html>

Thanks in advance!

Adrian

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

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

发布评论

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

评论(3

独留℉清风醉 2024-08-16 11:28:51

您肯定会因为重复的“Tabs”ID 属性而遇到一些麻烦。以下示例应该可以实现您的需求:
主文件(外部选项卡)

<html>
<head id="Head1" runat="server">
    <title></title>
    <link type="text/css" href="http://static.jquery.com/ui/themes/base/ui.base.css"
      rel="stylesheet" />
    <link type='text/css' href='http://static.jquery.com/ui/themes/base/ui.tabs.css'
      rel='stylesheet'>
    <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.tabs.js"></script>

</head>
<body>
  <div id="OuterTab">
    <ul>
      <li><a href="#InnerTab1" title="InnerTab1"><span>InnerTab1</span></a></li>
      <li><a href="#InnerTab2" title="InnerTab2"><span>InnerTab2</span></a></li>
    </ul>
    <div id="InnerTab1">   
    </div>
    <div id="InnerTab2">
    </div>
  </div>
      <script type="text/javascript">
        $(function() {
            $("#OuterTab").tabs();
            $('#InnerTab1').load('tab1.html', function() {
              $('#tabs').tabs();
            });
            $('#InnerTab2').load('tab2.html', function() {
              $('#tabs2').tabs();
            });
        });
    </script>
</body>
</html>  

选项卡 1 (tab1.html)

<div id="tabs">
  <ul>
    <li><a href="#tabB1"><span>InnerTabB1</span></a></li>
    <li><a href="#tabB2"><span>InnerTabB2</span></a></li>
  </ul>
  <div id="tabB1">
    This is tab b1 content
  </div>
  <div id="tabB2">
    This is tab b2 content
  </div>
</div>

选项卡 2 (tab2.html)

<div id="tabs2">
  <ul>
    <li><a href="#tabA1"><span>InnerTabA1</span></a></li>
    <li><a href="#tabA2"><span>InnerTabA2</span></a></li>
  </ul>
  <div id="tabA1">
    This is tab A1 content
  </div>
  <div id="tabA2">
    This is tab A2 content
  </div>
</div>

这样,当您运行主文件时,这两个选项卡文件通过 jQuery 请求并加载到相应的 div 中。然后我定义了一个回调来激活刚刚加载的选项卡。

如果您需要更多详细信息,请继续发表评论。

You are definitely running into a little bit of trouble with your duplicated 'Tabs' ID attribute. The following example should achieve what you're looking for:
Main File (Outer Tab)

<html>
<head id="Head1" runat="server">
    <title></title>
    <link type="text/css" href="http://static.jquery.com/ui/themes/base/ui.base.css"
      rel="stylesheet" />
    <link type='text/css' href='http://static.jquery.com/ui/themes/base/ui.tabs.css'
      rel='stylesheet'>
    <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.tabs.js"></script>

</head>
<body>
  <div id="OuterTab">
    <ul>
      <li><a href="#InnerTab1" title="InnerTab1"><span>InnerTab1</span></a></li>
      <li><a href="#InnerTab2" title="InnerTab2"><span>InnerTab2</span></a></li>
    </ul>
    <div id="InnerTab1">   
    </div>
    <div id="InnerTab2">
    </div>
  </div>
      <script type="text/javascript">
        $(function() {
            $("#OuterTab").tabs();
            $('#InnerTab1').load('tab1.html', function() {
              $('#tabs').tabs();
            });
            $('#InnerTab2').load('tab2.html', function() {
              $('#tabs2').tabs();
            });
        });
    </script>
</body>
</html>  

Tab 1 (tab1.html)

<div id="tabs">
  <ul>
    <li><a href="#tabB1"><span>InnerTabB1</span></a></li>
    <li><a href="#tabB2"><span>InnerTabB2</span></a></li>
  </ul>
  <div id="tabB1">
    This is tab b1 content
  </div>
  <div id="tabB2">
    This is tab b2 content
  </div>
</div>

Tab 2 (tab2.html)

<div id="tabs2">
  <ul>
    <li><a href="#tabA1"><span>InnerTabA1</span></a></li>
    <li><a href="#tabA2"><span>InnerTabA2</span></a></li>
  </ul>
  <div id="tabA1">
    This is tab A1 content
  </div>
  <div id="tabA2">
    This is tab A2 content
  </div>
</div>

This way, when you run your main file, the two tab files are requested via jQuery and loaded into the appropriate divs. Then I have defined a callback to activate the tabs that were just loaded.

If you need more details just follow up with a comment.

单身情人 2024-08-16 11:28:51

一旦调用了一个innerTab页面,所有的HTML元素就会立即呈现。您可能会遇到 ID 字段的多个副本的问题,例如“选项卡”... JQuery 正在引用 $(“#tabs”),但存在两个。

你能把JQuery错误贴出来吗?

Once you called a innerTab page, all the HTML elements become rendered at once. You could be having issues with multiple copies of ID fields, such as "tabs"... The JQuery is referencing $("#tabs"), but there are two present.

Can you please post the JQuery error?

向地狱狂奔 2024-08-16 11:28:51

如果您通过 ajax 获取内部选项卡,请不要包含完整的 html 文档和 jquery,所有内容都将在 javascript 中重新定义并且存在冲突。

只需删除整个 head、body 和 html 包装标签,留下 , 就可以了。

您还需要在加载选项卡时重新定义选项卡。添加回调到 ajax 选项卡函数 -- (类似 function ontabAJAX(){ if ($('.tab .active .innertabs').length)){ $('.tab .active .innertabs') .removeClass('innertabs').addClass('tabbed').tabs() })。

If you are fetching the inner tabs through ajax, don't include a full html document and jquery, everything is being redefined in javascript and is conflicting.

Simply remove the whole head, body, and html wrapper tags leaving the , and it should work.

You also need to redefine the tabs when they it is loaded. Add a callback to the ajax tabs function -- (something like function ontabAJAX(){ if ($('.tab .active .innertabs').length)){ $('.tab .active .innertabs').removeClass('innertabs').addClass('tabbed').tabs() }).

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