简体   繁体   English

jQuery UI选项卡:如果活动选项卡中的表单输入包含内容,则不允许用户切换选项卡

[英]jQuery UI Tabs: Don't let user switch tabs if form input in active tab has content

I'm using jQuery UI Tabs, and these tabs are inside a form. 我正在使用jQuery UI选项卡,这些选项卡位于表单内。 Every tab contains a number of form fields, which can be filled. 每个选项卡都包含许多可以填写的表单字段。 It looks something like this: 看起来像这样:

<form>
<tab1 href=tabcontent1> <tab2 href=tabcontent2> <tab3 href=tabcontent3>

<div tabcontent1>
<input field>
<input field>
</div>

<div tabcontent2>
<input field>
<input field>
</div>

<div tabcontent3>
<input field>
<input field>
</div>

<submit button>
</form>

Problem is, If the user for example have started filling the fields of tab1, I don't want the user to be able to fill the fields of tab2 or tab3. 问题是,例如,如果用户已开始填充tab1的字段,我不希望用户能够填充tab2或tab3的字段。

So, I'm looking for a way to check if the user have started to fill the input fields of a tab, and if this is the case, hide the other tabs / disable switching to the other tabs. 因此,我正在寻找一种方法来检查用户是否已开始填充选项卡的输入字段,如果是这种情况,请隐藏其他选项卡/禁用切换至其他选项卡。

If the user removes the stuff he has written, he should once again be able to switch tabs. 如果用户删除了他写的内容,则他应该能够再次切换标签。

Thanks for your help, it's greatly appreciated! 多谢您的协助,不胜感激!

// Jens. // Jens。

You could have used beforeActivate function of jQuery tab to do this. 您可能已经使用jQuery选项卡的beforeActivate函数来执行此操作。 Since your code is not complete and hence not clear, I will just take the sample example from jQuery tabs documentation: 由于您的代码不完整,因此不清楚,因此,我仅从jQuery选项卡文档中获取示例示例:

JS: JS:

$(function () {
    $("#tabs").tabs({
        beforeActivate: function (event, ui) {
            var content = ui.oldPanel; // Get current content
            var input = $(content).find('input.i'); //Get input
            if (input.val()) { // Check if input has any value or whatever condition you want.
                alert('not allowed');
                return false; //Stop loading new tab if condition is satisfied.
            }
        }
    });
});

Demo: http://jsfiddle.net/lotusgodkk/GCu2D/416/ 演示: http//jsfiddle.net/lotusgodkk/GCu2D/416/

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

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