简体   繁体   English

jQuery选项卡不起作用

[英]jQuery tabs not working

I'm trying to implement jQuery tabs to replace AJAX tab container. 我正在尝试实现jQuery选项卡来替换AJAX选项卡容器。 I've followed the code from the jquery website but my tabs aren't showing up. 我已经关注了jquery网站上的代码,但我的标签没有显示出来。 It just loads the entire page full of data with no tabs. 它只是加载整个页面,没有任何标签。 And firebug tells me the following error: 萤火虫告诉我以下错误:

$("#tabs").tabs is not a function

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

I've got references to all the files needed: 我已经获得了所需的所有文件:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

And I've got the function specified as follows: 我有如下指定的功能:

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

  </script>

The code for the tabs are as follows: 选项卡的代码如下:

div id="tabs">
    <ul>
        <li><a href="#tab-1"><span>Patient Information</span></a></li>
        <li><a href="#tab-2"><span>Medical History 1 of 3</span></a></li>
        <li><a href="#tab-3"><span>Medical History 2 of 3</span></a></li>
        <li><a href="#tab-4"><span>Medical History 3 of 3</span></a></li>
        <li><a href="#tab-5"><span>Scheduler</span></a></li>
        <li><a href="#tab-6"><span>Care Plan</span></a></li>
    </ul> 
<div id="tab-1">
</div>
**Repeats for all tabs through tab-6**
</div>

Can anyone tell me what I'm doing wrong? 谁能告诉我我做错了什么? Since the .tabs() function isn't working the page is just loading like so - 由于.tabs()函数不起作用,页面只是像这样加载 - 没有标签

Your code works just fine. 你的代码工作得很好。 The only thing you're missing is the CSS for the tabs - http://jsfiddle.net/8JX4A/ 你唯一缺少的是标签的CSS - http://jsfiddle.net/8JX4A/

If you have another jQuery element in the same page maybe you have conflicts. 如果您在同一页面中有另一个jQuery元素,则可能存在冲突。 I have the same problem, try with this: 我有同样的问题,试试这个:

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

Then only change i:; jQuery.noConflict(); 然后只改变i:; jQuery.noConflict(); i:; jQuery.noConflict(); before each jQuery element. 在每个jQuery元素之前。

您需要链接CSS文件: http//jsfiddle.net/fJaBa/

$.fn.tabs = function() {
    var selector = this;

    this.each(function() {
        var obj = $(this); 

        $(obj.attr('href')).hide();

        $(obj).click(function() {
            $(selector).removeClass('active');

            $(selector).each(function(i, element) {
                $($(element).attr('href')).hide();
            });

            $(this).addClass('active');

            $($(this).attr('href')).fadeIn();

            return false;
        });
    });

    $(this).show();

    $(this).first().click();
};

Live Demo Here 现场演示

Try loading scripts in this sequence 尝试按此顺序加载脚本

<script src="../../jquery-1.7.1.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.tabs.js"></script>

Not a jquery expert but I do know you will need some css to make the tabs work correctly. 不是jquery专家,但我知道你需要一些css来使标签正常工作。 since they will need to be positioned relative. 因为它们需要相对定位。 Also check out this jquery tabs tutorial to compare your code. 另请查看此jquery选项卡教程以比较您的代码。

Is the 1.8 alias to the jQuery UI lib working? jQuery UI lib的1.8别名是否正常工作? Have you tried using a specific full version, like 1.8.16 instead? 您是否尝试使用特定的完整版本,例如1.8.16 Can you look at the page once it's loaded and see if jQuery and/or jQuery UI were actually pulled in successfully? 你可以看一下它加载后的页面,看看jQuery和/或jQuery UI是否真的被成功拉入了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM