无法检索jquery当前选项卡索引

时间:2013-03-17 17:12:50

标签: jquery jquery-ui tabs

每次点击按钮我都希望得到所选标签的索引,而不是我的空白

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery UI Tabs Example 1</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js'></script>
<script>
$(function() {

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

    $("#button").click(function() {
        var current_index = $("#tabs").tabs("option","selected");
        alert("The index of the current tab is " + current_index);
    });
});
</script>
</head>
<body>
<button id="button">Click me</button>

<div id="tabs">
    <ul>
        <li><a href="/buildFirstTab">First Tab</a></li>
        <li><a href="/buildSecondTab">Second Tab</a></li>
        <li><a href="/buildThirdTab">Third Tab</a></li>
    </ul>    
</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js'></script>

只需用新的链接替换j Query Ui Lib链接..

更新代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery UI Tabs Example 1</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js'></script>

<script>
$(function() {

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

    $("#button").click(function() {
        var current_index = $("#tabs").tabs("option","selected");
        alert("The index of the current tab is " + current_index);
    });
});
</script>
</head>
<body>
<button id="button">Click me</button>

<div id="tabs">
    <ul>
        <li><a href="/buildFirstTab">First Tab</a></li>
        <li><a href="/buildSecondTab">Second Tab</a></li>
        <li><a href="/buildThirdTab">Third Tab</a></li>
    </ul>    
</div>

</body>
</html>