jQuery 选项卡:如何禁止切换到特定选项卡?
我正在使用 jQuery 选项卡。
某些选项卡需要用户输入。
一旦用户切换到其他选项卡,这些输入值就会得到验证。
现在我的问题是:
只要这些输入值错误,如何防止显示任何其他选项卡?
$("#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?
*/
}
})
感谢您的宝贵时间
I am using 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要做的就是从函数返回 false,它将阻止选择选项卡。请参阅 示例,了解如何防止表单验证失败时选择选项卡,网址为jQuery 网站。
All you need to do is return false from the function and it will prevent selecting the tab. See the example on how to prevent tab selection on form validation failure at the jQuery site.
您可以使用 UI 选项卡选项禁用选项卡。然后它们会变灰且不可点击。
因此,您只需禁用除所选选项卡之外的所有其他选项卡。但这意味着,您必须在用户单击选项卡之前验证表单。
You can disable your tabs with the UI tabs options. Then they are greyed out and not clickable.
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.