寻求一些帮助,试图获取两个选定按钮的值,添加它们,然后输出答案......
我在这里整理了一个js fiddle,而 jQuery 从来都不是我的强项,所以我很难理解引导程序的单选按钮,这些单选按钮实际上不是“传统”单选按钮......
<div class="control-group">
<h4>How much you wanna give me today?</h4>
<div class="controls">
<div class="btn-group" id="pay-me-friend" data-toggle="buttons-radio">
<button type="button" name="dollar" class="btn" value="100">$100</button>
<button type="button" name="dollar" class="btn" value="200">$200</button>
<button type="button" name="dollar" class="btn" value="300">$300</button>
<button type="button" name="dollar" class="btn" value="400">$400</button>
</div>
</div>
</div>
<div class="control-group">
<h4>How much you wanna multiply that by?</h4>
<div class="controls">
<div class="btn-group" id="pay-me-multiply" data-toggle="buttons-radio">
<button type="button" name="multiple" class="btn" value="1">1</button>
<button type="button" name="multiple" class="btn" value="2">2</button>
<button type="button" name="multiple" class="btn" value="3">3</button>
<button type="button" name="multiple" class="btn" value="4">4</button>
</div>
</div>
</div>
<hr>
<div class="well">Total amount you'll pay me: <span id="displaynumber"></span></div>
这是我使用 javascript 的起点......我还应该补充一点,我想使用 keyup 函数,这样答案就可以随时改变......
$('#pay-me-friend > button.active').keyup(function(){
var no1 = $('#pay-me-friend > button.active').val();
var no2 = $('#pay-me-multiply > button.active').val();
$('#displaynumber').html(no1 + no2);
});