Bootstrap单选按钮不起作用

MCM*_*ery 5 html twitter-bootstrap twitter-bootstrap-4 bootstrap-4

我在Bootstrap 4中使用单选按钮,如下所示:

    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
            <input type="radio" id="physical-option" onclick="alert('Physical!')" checked="checked" /> Physical
        </label>
        <label class="btn btn-primary">
            <input type="radio" id="scenery-option" onclick="alert('Scenery!')" /> Scenery
        </label>
    </div>
Run Code Online (Sandbox Code Playgroud)

你可以看到我在那里有onclicks.但是,当我点击它们时,没有任何反应!这是Bootstrap中的错误吗?

Jos*_*ung 2

你能把 onclick 放在标签上而不是 radio 上吗?我认为引导程序使标签成为单选触发器而不是实际的单选按钮。

看看风景按钮:

https://jsfiddle.net/zf7p2Lbd/

    <label class="btn btn-primary" onclick="alert('Scenery!')">
        <input type="radio" id="scenery-option" /> Scenery
    </label>
Run Code Online (Sandbox Code Playgroud)