1

每次我单击按钮时,我都希望获得所选选项卡的索引,而不是我得到 null

<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>
4

1 回答 1

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>
于 2013-03-17T17:26:41.620 回答