我想做的是收集所有选择菜单中的所有值。but When choosing a decimal number not correctly added.
jQuery代码:
var total = 0;
function calcTotal()
{
$("input:checked,select").each(function()
{
//This happens for each checked input field
var value = $(this).attr("value");
total += parseInt(value);
var prog = $('select[name="prog"] option:selected').text();
$("#prog1").val(prog);
var ticket = $('select[name="ticket"] option:selected').text();
$("#ticket1").val(ticket);
var skn = $('select[name="skn"] option:selected').text();
$("#skn1").val(skn);
var buy = $('input[name=buy]:checked').text()
$("#buy1").val(buy);
});
}
//This happens when the page loads
calcTotal();
$("#total").val(total);
$("input:checkbox, input:radio,select,selected").click(function()
{
total = 0;
calcTotal();
$("#total").val(total);
});
HTML 代码:
<form method="POST" >
<select name="logah" style="padding: 3px;">
<option value="0">--</option>
<option value="1" >1</option>
<option value="1.5" >1.5</option>
<option value="2.5" >2.5</option>
</select>
<select name="select2" style="padding: 3px;">
<option value="0">--</option>
<option value="1" >1</option>
<option value="2" >6</option>
</select>
我想对选择菜单中的所有值求和。