Bootbox中的多个输入

kam*_*mbi 22 javascript twitter-bootstrap bootbox

如何在Bootstrap的Bootbox中有两个输入而不是一个输入?

我需要在模态对话框中接收2个值.

har*_*ith 47

实际上,有一种更简单的方法,它不需要您修改bootbox代码.

您在创建引导箱时传递的字符串不必仅是文本:它也可以是html代码.这意味着您可以在框中包含几乎所有内容.

要将自定义表单放入引导箱,您可以按如下方式创建它:

bootbox.confirm("<form id='infos' action=''>\
    First name:<input type='text' name='first_name' /><br/>\
    Last name:<input type='text' name='last_name' />\
    </form>", function(result) {
        if(result)
            $('#infos').submit();
});
Run Code Online (Sandbox Code Playgroud)


igo*_*gor 8

我刚刚为此制作了功能,请查看 - 这里

用法示例

bootbox.form({
    title: 'User details',
    fields: {
        name: {
            label: 'Name',
            value: 'John Connor',
            type:  'text'
        },
        email: {
            label: 'E-mail',
            type:  'email',
            value: 'johnconnor@skynet.com'
        },
        type: {
            label: 'Type',
            type:  'select',
            options: [
                {value: 1, text: 'Human'},
                {value: 2, text: 'Robot'}
            ]
        },
        alive: {
            label: 'Is alive',
            type: 'checkbox',
            value: true
        },
        loves: {
            label: 'Loves',
            type: 'checkbox',
            value: ['bike','mom','vg'],
            options: [
                {value: 'bike', text: 'Motorbike'},
                {value: 'mom', text: 'His mom'},
                {value: 'vg', text: 'Video games'},
                {value: 'kill', text: 'Killing people'}
            ]
        },
        passwd: {
            label: 'Password',
            type: 'password'
        },
        desc: {
            label: 'Description',
            type: 'textarea'
        }
    },
    callback: function (values) {
        console.log(values)
    }
})
Run Code Online (Sandbox Code Playgroud)


Nat*_*aye 5

对我来说,这是最干净的方法:

var form = $('<form><input name="usernameInput"/></form>');
bootbox.alert(form,function(){
    var username = form.find('input[name=usernameInput]').val();
    console.log(username);
});
Run Code Online (Sandbox Code Playgroud)