Javascript 如何获取使用twitter引导创建的按钮的值?

Javascript 如何获取使用twitter引导创建的按钮的值?,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我使用下面的HTML代码创建按钮。我已经将引导中的类应用于这些按钮 <label class="help-block" for="xlInput">Monetization</label> <div id="revsource" class="btn-group" data-toggle="buttons-checkbox"> <button id="revenueSource" class="btn monibtn active" value="1"

我使用下面的HTML代码创建按钮。我已经将引导中的类应用于这些按钮

<label class="help-block" for="xlInput">Monetization</label>
<div id="revsource" class="btn-group" data-toggle="buttons-checkbox">
<button id="revenueSource" class="btn monibtn active" value="1" data-toggle="button" type="button">Advertise</button>
<button id="revenueSource" class="btn monibtn" value="2" data-toggle="button" type="button">License</button>
<div class="controls">
<input id="revenueSource1" type="hidden" 0="0" name="data[RevenueSource][revenue_source_id]" value="1,2">
</div>
</div>
您可以与目标选择器一起使用
.monibtn.active

$('.monibtn').click(function () {
    //get all .monibtn elements with class active and create an array with the value of those elements
    var selected = $('.monibtn.active').map(function () {
        return this.value;
    }).get();
    //assing the value of the selected array to the target element
    $('#revenueSource1').val(selected.join());
});

ID必须是唯一的。代码中有两个ID相同的元素。@NoobEditor它返回一个新的jQuery对象,该对象包含回调函数返回的值,请参见
$('.monibtn').click(function () {
    //get all .monibtn elements with class active and create an array with the value of those elements
    var selected = $('.monibtn.active').map(function () {
        return this.value;
    }).get();
    //assing the value of the selected array to the target element
    $('#revenueSource1').val(selected.join());
});