简体   繁体   English

如何在启动箱上设置tabindex?

[英]How to set tabindex on bootbox?

I have a custom confirm dialog and I want to have the tabindex on the btn-danger button so I can submit the form with enter. 我有一个自定义的确认对话框,我想在btn-danger按钮上具有tabindex,以便我可以使用enter提交表单。

How to achieve that? 如何实现呢?

var config = {
    title: 'Confirm approval removal',
    message: "<em>" + self.$label.text() + "</em> is about to be removed. Please confirm the action.",
    buttons: {
        'cancel': {
            label: 'Keep approval',
            className: 'btn-default'
        },
        'confirm': {
            label: 'Remove approval',
            className: 'btn-danger'
        }
    },
    callback: function(result) {
        if (result) {
            self.$approvedCheckbox.prop('checked', false);
        } else {
            self.$approvedCheckbox.prop('checked', true);
            self.$requiredCheckbox.prop('checked', false);
        }

        self.markRequiredFields();
    }
};

bootbox.confirm(config);

I tried adding tabindex attributes but it did not work. 我尝试添加tabindex属性,但是没有用。

The button which has the btn-primary class will get autofocus for enter completion. 具有btn-primary类的按钮将自动聚焦以完成输入。 It also works together with btn-danger : 它也可以和btn-danger一起使用:

var config = {
    ...
    buttons: {
        'cancel': {
            label: 'Keep approval',
            className: 'btn-default'
        },
        'confirm': {
            label: 'Remove approval',
            className: 'btn-danger btn-primary' // this button will get the index and will be submitted on enter
        }
    },
    ...
};


bootbox.confirm(config);

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

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