简体   繁体   English

jQueryUI选项卡禁用方法不起作用:禁用所有选项卡

[英]jQueryUI tabs disable method not working: disables all tabs when it should not

When I call the disable method, all the jQueryUI tabs become disabled, including the one (index 1) I left out of the index array. 当我调用disable方法时,所有jQueryUI选项卡都会被禁用,包括我从索引数组中遗漏的一个(索引1)。 Here is a sample: 这是一个示例:

<div id="tabs">
  <ul>
    <li><a href="#tabs1">one</a></li>
    <li><a href="#tabs2">two</a></li>
    <li><a href="#tabs3">three</a></li>
    <li><a href="#tabs4">four</a></li>
    <li><a href="#tabs5">five</a></li>
  </ul>

  <div id="tabs1" style="display: none;"><p>tab 1 content</p></div>
  <div id="tabs2" style="display: none;"><p>tab 2 content</p></div>
  <div id="tabs3" style="display: none;"><p>tab 3 content</p></div>
  <div id="tabs4" style="display: none;"><p>tab 4 content</p></div>
  <div id="tabs5" style="display: none;"><p>tab 5 content</p></div>
</div>

<script>
    function disableAllExcept1(){
        $('#tabs').tabs('option', 'disabled', [0,2,3,4,5]);
        $('#tabs').tabs('option', 'active', 1);
    }

    $(function() {
        $( "#tabs" ).tabs();
        disableAllExcept1();
    });
</script>

Why is it disabling tab two (index 1)? 为什么禁用第二个选项卡(索引1)?

The problem was an extra index in the array. 问题是数组中有一个额外的索引。 I had removed a tab but had not removed the index (5) from the array. 我删除了一个选项卡,但没有从数组中删除索引(5)。 The behavior seems odd though, maybe even buggy. 但是,这种行为似乎很奇怪,甚至可能是越野车。 I would expect it to just ignore the extra index or emit a warning or error. 我希望它只是忽略多余的索引,或者发出警告或错误。

This: 这个:

$('#tabs').tabs('option', 'disabled', [0,2,3,4,5]);

Should have been this: 应该是这样的:

$('#tabs').tabs('option', 'disabled', [0,2,3,4]);

Here's a jsfiddle demonstrating the issue: http://jsfiddle.net/spencerw/hmno6ekb/ 这是一个演示问题的jsfiddle: http : //jsfiddle.net/spencerw/hmno6ekb/

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

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