JQuery UI 选项卡不工作

发布于 2024-09-02 13:01:42 字数 3322 浏览 4 评论 0原文

我正在使用 JQuery 网站上的以下确切示例,使用其内置选项卡功能:

<script type="text/javascript">
 $(function() {
  $("#tabs").tabs();
 });
 </script>



<div class="demo">

<div id="tabs">
 <ul>
  <li><a href="#tabs-1">Nunc tincidunt</a></li>
  <li><a href="#tabs-2">Proin dolor</a></li>
  <li><a href="#tabs-3">Aenean lacinia</a></li>
 </ul>
 <div id="tabs-1">
  <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
 </div>
 <div id="tabs-2">
  <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
 </div>
 <div id="tabs-3">
  <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
  <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
 </div>
</div>

</div><!-- End demo -->

<div style="display: none;" class="demo-description">

<p>Click tabs to swap between content that is broken into logical sections.</p>

</div><!-- End demo-description -->

但是,当我将 JQuery Accordian 插件放置在 tabs-1、tabs-2 或 tabs-3 元素中的任何位置时,它会停止正常工作,但是它在不使用 Jquery 的普通页面中工作正常。或者任何其他 Jquery 似乎都无法在任何选项卡 DIV 中工作。有什么想法吗?

I am using the exact example below from the JQuery website using its built in tabs functions:

<script type="text/javascript">
 $(function() {
  $("#tabs").tabs();
 });
 </script>



<div class="demo">

<div id="tabs">
 <ul>
  <li><a href="#tabs-1">Nunc tincidunt</a></li>
  <li><a href="#tabs-2">Proin dolor</a></li>
  <li><a href="#tabs-3">Aenean lacinia</a></li>
 </ul>
 <div id="tabs-1">
  <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
 </div>
 <div id="tabs-2">
  <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
 </div>
 <div id="tabs-3">
  <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
  <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
 </div>
</div>

</div><!-- End demo -->

<div style="display: none;" class="demo-description">

<p>Click tabs to swap between content that is broken into logical sections.</p>

</div><!-- End demo-description -->

However, when I place the JQuery Accordian plugin anywhere in the tabs-1, tabs-2, or tabs-3 element, it stops working correctly, but it works fine in a normal page that doesn't use Jquery. Or any other Jquery doesn't seem to work as its in any of the tabs DIVs. Any ideas?

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

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

发布评论

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

评论(4

-残月青衣踏尘吟 2024-09-09 13:01:42
<script type="text/javascript">
 $(function() {
  $("#tabs").tabs();
 });
 </script>

在元素存在之前调用。所以

要么把它全部放在 html 的底部,就在“”上方,

要么替换

 $("#tabs").tabs(); 

$(document).ready(function (){ $("#tabs").tabs(); });
<script type="text/javascript">
 $(function() {
  $("#tabs").tabs();
 });
 </script>

is called before the elements even exist. so

either put it all at the bottom of your html just above the ""

or replace

 $("#tabs").tabs(); 

with

$(document).ready(function (){ $("#tabs").tabs(); });
白云不回头 2024-09-09 13:01:42

您的包含内容是什么样的?路径正确吗?

顺便说一句,我在项目中使用了一段时间 JQuery UI 选项卡,但过了一段时间就用纯 HTML/CSS 替换了。这是一个关于编写 CSS 选项卡的精彩教程。甚至不需要 JavaScript。

有时,这些预先打包的组件试图做太多事情,但最终却使一个非常简单的任务变得比它需要的更加复杂。

What do your includes look like? Are the paths correct?

On a side note, I used JQuery UI Tabs in a project for a while, but replaced in with plain HTML/CSS after a while. Here is a great tutorial on writing CSS tabs. Not even javascript is required.

Sometimes these prepackaged components try to do too much but end up making a very simple task more complex than it needs to be.

暖风昔人 2024-09-09 13:01:42

它应该有效。我做了一个工作示例:
http://jsfiddle.net/nhAJz/

将手风琴嵌套在选项卡中。
所以这可能是一个CSS问题,你能用jsfiddle重现它吗?这样我们就有了您的手风琴 js 和 css 标记吗?

It should work. I have made a working example:
http://jsfiddle.net/nhAJz/

having the accordion nested in a tab.
So it is probably a css issue, can you reproduce it using jsfiddle? so that we have exactly your accordion js and css markup?

秋叶绚丽 2024-09-09 13:01:42

我刚刚完成了这个,你可以使用它。它不是 LI 或 UI 选项卡,但它具有相同的功能,只是采用我自己的样式。

$(document).ready(function () {
$('#Tab1').click(function () {
    $('#TheStreets').hide();
    $('#DownTown').hide();
    $('#Underground').fadeIn(300);
    $('#Tab1').removeClass('NonCurrentTab').addClass('CurrentTab');
    $('#Tab2').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab3').removeClass('CurrentTab').addClass('NonCurrentTab');
});
$('#Tab2').click(function () {
    $('#Underground').hide();
    $('#DownTown').hide();
    $('#TheStreets').fadeIn(300);
    $('#Tab1').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab2').removeClass('NonCurrentTab').addClass('CurrentTab');
    $('#Tab3').removeClass('CurrentTab').addClass('NonCurrentTab');
});
$('#Tab3').click(function () {
    $('#Underground').hide();
    $('#TheStreets').hide();
    $('#DownTown').fadeIn(300);
    $('#Tab1').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab2').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab3').removeClass('NonCurrentTab').addClass('CurrentTab');
});
});

这是 JsFiddle 的完整编码
完整编码

I just finished this, you can use it at your use. It's not LI or UI Tabs, but it's the same function, just in my own styling of things.

$(document).ready(function () {
$('#Tab1').click(function () {
    $('#TheStreets').hide();
    $('#DownTown').hide();
    $('#Underground').fadeIn(300);
    $('#Tab1').removeClass('NonCurrentTab').addClass('CurrentTab');
    $('#Tab2').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab3').removeClass('CurrentTab').addClass('NonCurrentTab');
});
$('#Tab2').click(function () {
    $('#Underground').hide();
    $('#DownTown').hide();
    $('#TheStreets').fadeIn(300);
    $('#Tab1').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab2').removeClass('NonCurrentTab').addClass('CurrentTab');
    $('#Tab3').removeClass('CurrentTab').addClass('NonCurrentTab');
});
$('#Tab3').click(function () {
    $('#Underground').hide();
    $('#TheStreets').hide();
    $('#DownTown').fadeIn(300);
    $('#Tab1').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab2').removeClass('CurrentTab').addClass('NonCurrentTab');
    $('#Tab3').removeClass('NonCurrentTab').addClass('CurrentTab');
});
});

Here's the Full Coding at JsFiddle
Full Coding

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