代码之家  ›  专栏  ›  技术社区  ›  user3408779

如何在bootbox提示符下默认选中radiobutton

  •  0
  • user3408779  · 技术社区  · 7 年前

    我能够显示单选按钮使用引导盒提示。但默认情况下,我没有选中单选按钮。如何做到这一点。这是我显示单选按钮的代码。

    bootbox.prompt({
        title: "This is a prompt with a set of Radiobutton inputs!",
        inputType: 'radio',
        inputOptions: [
            {
                text: 'EU Format',
                value: '1',
                checked: true,
            },
            {
                text: 'Standard Format',
                value: '2',
            }
        ],
        callback: function (result) {
            console.log(result);
        }
        });
    

    我补充说 checked: true, 试过了吗 checked : "checked"

    1 回复  |  直到 7 年前
        1
  •  1
  •   Tieson T.    6 年前

    这实际上包含在文档中, here . 我以前也回答过这个问题,但由于我目前没有这个答案的链接,所以您需要这样做:

    bootbox.prompt({
        title: "This is a prompt with a set of Radiobutton inputs!",
        inputType: 'radio',
        value: '1', /* value sets the initial checked item */
        inputOptions: [
            {
                text: 'EU Format',
                value: '1',
                checked: true,
            },
            {
                text: 'Standard Format',
                value: '2',
            }
        ],
        callback: function (result) {
            console.log(result);
        }
    });
    

    单选按钮和复选框之间的唯一区别是,只能使用收音机设置单个值。请注意,类型必须匹配。在你的例子中, '1' 会有用的,但是 1 不会,因为前者是字符串,而后者是数字。在检查 value

    既然你引用的是无线电类型,我猜你使用的是5.x版本?如果是这样,我有一个工作进行中的文件更新 here ,直到我可以推出5.x版本。旧文件仍然有效,但它(显然?)没有记录一些新功能。