简体   繁体   English

jQuery Tabs:如何禁止切换到特定选项卡?

[英]jQuery Tabs: How to disallow switching to a specific tab?

I am using jQuery Tabs . 我正在使用jQuery Tabs

Some Tabs require user input. 一些选项卡需要用户输入。

As soon as the user switches to an other tab these input values are validated. 用户一旦切换到其他选项卡,这些输入值便会得到验证。

Now here is my question: 现在这是我的问题:

How can I prevent showing any other tab as long as these input values are wrong? 只要这些输入值错误,如何防止显示其他标签?

$("#tab").bind('tabsselect', function(){

   if ( ... )
   {
       alert ( 'Please fill all required fields before proceeding' );

      /*         
            What code do I have to place here to prevent displaying this tab?
      */

    }   

})

Thank you for your time 感谢您的时间

All you need to do is return false from the function and it will prevent selecting the tab. 您需要做的就是从函数返回false,这将阻止选择选项卡。 See the example on how to prevent tab selection on form validation failure at the jQuery site. 请参阅jQuery网站上有关如何防止表单验证失败时选择选项卡的示例

You can disable your tabs with the UI tabs options. 您可以使用UI选项卡选项禁用选项卡。 Then they are greyed out and not clickable. 然后它们变成灰色,不可点击。

$('.selector').tabs('option', 'disabled', [1, 2]);

So you just disable every other tab that is not the selected one. 因此,您只需禁用所有其他非选定选项卡。 That would mean though, that you will have to validate the form before the user clicks the tab. 但是,这意味着您将必须在用户单击选项卡之前验证表单。

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

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