简体   繁体   English

将Click事件附加到Bootstrap切换单选按钮

[英]Attaching Click event to Bootstrap Toggle Radio Buttons

I have a boostrap toggle with the code below. 我有一个带有下面代码的boostrap切换。 It is visually working right 它在视觉上正常工作

<div class="btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
            <input type="radio" name="options" id="showBuildQuantity" autocomplete="off" checked>Build Quantity
        </label>
        <label class="btn btn-primary">
            <input type="radio" name="options" id="showNumberOfScreens" autocomplete="off" onclick="showBuildQuantity()">Number of Screens
        </label>
    </div>

Below it I have some code to handle click events: 在它下面我有一些代码来处理点击事件:

$(document).ready(function () {
    $('#showBuildQuantity').on('click', function () {
        <code here>
    });

    $('#showNumberOfScreens').on('click', function () {
        <code here>
    });
});

The issue I am having is that the click event's are never run when I click the toggle buttons. 我遇到的问题是,当我单击切换按钮时,点击事件永远不会运行。

I have other buttons on the same page using the same kind of jQuery click event and they do not have an issue. 我使用相同类型的jQuery点击事件在同一页面上有其他按钮,但它们没有问题。

After some research I found I need to use change instead of click. 经过一些研究后,我发现我需要使用更改而不是点击。 So the code should look like this: 所以代码应如下所示:

$('#showBuildQuantity').on('change', function () {
    if (myChart != null) {
        myChart.destroy();
    }
    setChart(getBuildQuantityData);
});

$('#showNumberOfScreens').on('change', function () {
    if (myChart != null) {
        myChart.destroy();
    }
    setChart(getNumScreensData);
});

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

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