简体   繁体   English

jQuery UI标签+对话框+表单标签顺序

[英]Jquery ui tabs+dialog+form tab order

I have a jquery dialog that pops up with a form. 我有一个弹出对话框的jQuery对话框。 The form is split across multiple tabs within the dialog. 对话框中的多个选项卡均分为该表格。 I'm working on keyboard ease and would like for pushing the tab key on the last element of one tab to take me to the first element of the next tab. 我正在努力简化键盘,并希望在一个标签的最后一个元素上按Tab键,将我带到下一个标签的第一个元素。 Right now the tab order is to go through the dialog tabs, then through the first tab of inputs, then to the OK button. 现在,选项卡顺序是依次通过对话框选项卡,输入的第一个选项卡和“确定”按钮。 Instead of Weight->OK I want it to go Weight->Price. 而不是Weight-> OK,我希望它为Weight-> Price。 Is there an easy way to do this? 是否有捷径可寻?

The HTML: HTML:

<div id='add_dialog' title='Add'>
    <form id="add_form" method="POST">
        <input type="hidden" name="action" value="add">
        <input type="hidden" name="ProductId" value="2">
        <div id="jquery-ui-tabs">
            <ul>
                <li><a href="#add_details">Details</a></li>
                <li><a href="#add_financial">Financial & Comments</a></li>
            </ul>

            <div id="add_details">                  
                Quantity: <input type="text" name="Quantity" value="1"><br />
                QuantityPerPack: <input type="text" name="QuantityPerPack" value="0"><br />
                Pc Weight: <input type="text" name="PieceWeight" value=" "><br />
            </div>
            <div id="add_financial">
                Price: <input type="text" name="PriceHigh" value="0.00"><br />
                Comment: <textarea name="StockComment"></textarea><br />
            </div>
        </div>
    </form>
</div>

And the initializing javascript: 并初始化javascript:

$('#add_dialog').dialog(
        { 
            autoOpen: false,
            maxHeight: 500,
            width: 600,
            minWidth: 600,
            zIndex: 99999,
            position: ['center', 50],
            buttons:[{
                text: "Ok",
                class: "dialog_ok",
                click: function() {
                $(this).dialog("close"); 
                    $("#add_form").submit();
                    }
                },
                {
                text: "Cancel",
                class: "dialog_cancel",
                click: function() {
                    $(this).dialog("close"); 
                }
            }]          
        });

It wasn't so bad. 还不错。 For posterity, here is the code I eventually used. 为了后代,这是我最终使用的代码。 I added IDs to the two inputs, then I attached a keydown event and if it's a tab I move to the next tab and then focus on the first element. 我在两个输入中添加了ID,然后附加了一个keydown事件,如果是选项卡,则移至下一个选项卡,然后将焦点放在第一个元素上。

$('#add_form_pieceweight').keydown(function(e) {
  var code = e.keyCode || e.which;
  if (code == '9') {
       $('#jquery-ui-tabs').tabs('select',1);
       $('#add_form_price').focus();
       return false;
  }
});

This is happening because the other form inputs are hidden in a hidden tab div, and thus skipped over for tabbing through. 之所以发生这种情况,是因为其他表单输入被隐藏在一个隐藏的选项卡div中,因此跳过了该选项卡。 So you have to manually listen for someone pressing tab and then show the other tab. 因此,您必须手动听某人的声音,然后按Tab键,然后显示其他选项卡。

On "weight" input, bind to keydown. 在“重量”输入上,绑定到按键。 Look at the key they pressed in the event that your lister gets. 查看他们在您的列表获取到时按下的键。 If someone pressed "tab", select the add_financial href and send it a "click" event to get it to change to the next tab, then select the "price" input and focus() on it. 如果有人按下“制表符”,请选择add_financial href并向其发送“点击”事件,以使其更改为下一个选项卡,然后选择“价格”输入并在其上关注focus()。

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

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