簡體   English   中英

將Click事件附加到Bootstrap切換單選按鈕

[英]Attaching Click event to Bootstrap Toggle Radio Buttons

我有一個帶有下面代碼的boostrap切換。 它在視覺上正常工作

<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>

在它下面我有一些代碼來處理點擊事件:

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

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

我遇到的問題是,當我單擊切換按鈕時,點擊事件永遠不會運行。

我使用相同類型的jQuery點擊事件在同一頁面上有其他按鈕,但它們沒有問題。

經過一些研究后,我發現我需要使用更改而不是點擊。 所以代碼應如下所示:

$('#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