如圖片公式那樣計算
function votecalculator(price, amount,poundage1){
price = parseFloat(price) || 0;
amount = parseFloat(amount) || 0;
poundage1 = parseFloat(poundage1) || 0;
var money2 = 0;
poundage = price*amout*(poundage1/100);
$("#poundage").val(poundage.toFixed(2));
}
$("#price").change(function () {
price = parseFloat($(this).val());
votecalculator(price, amount,poundage1);
});
$("#amount").change(function () {
amount = parseFloat($(this).val());
votecalculator(price, amount,poundage1);
});
$("#poundage1").change(function () {
poundage1 = parseFloat($(this).val());
votecalculator(price, amount,poundage1);
});
var price = parseFloat($("#price").val());
var amount = parseFloat($("#amount").val());
var poundage1 = parseFloat($("#poundage1").val());
votecalculator(price, amount,poundage1);
這是我的js 我只是計算了手續費 但是無法計算 不知道怎麼回事 還有就是$(document).ready() 就計算不了 必須刪除才能計算 還有就是 我想給他 同時計算 填完數量跟價格 金額和手續費都出現 就是在js裡先計算手續費 完了手續費有值了也計算 金額 但是要頁面要同時出現結果的 用什麼 if(){}嗎
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<div>
價格:<input type="text" id="price" />元/份<br />
數量:<input type="text" id="amount" />份
</div>
計算結果
<hr />
<table id="tbRst">
<tr><td> </td><td>金額</td><td>手續費</td><td>手續費率</td></tr>
<tr><td>申購</td><td><input type="text" />元</td><td><input type="text" />元</td><td><input type="text" value="1.5" id="poundage1" />%</td></tr>
<tr><td>認購</td><td><input type="text" />元</td><td><input type="text" />元</td><td><input type="text" value="1.2" id="poundage2" />%</td></tr>
<tr><td>贖回</td><td><input type="text" />元</td><td><input type="text" />元</td><td><input type="text" value="0.5" id="poundage3" />%</td></tr>
</table>
<script>
function votecalculator() {
var price = parseFloat($('#price').val()) || 0, amount = parseFloat($('#amount').val()) || 0, poundage,percent;
var ipts, money = price * amount;
$('#tbRst tr:gt(0)').each(function () {
ipts = $('input', this);
percent = parseFloat(ipts.eq(2).val()) || 0;
poundage = money * percent / 100;
ipts.eq(0).val((money + poundage).toFixed(2));
ipts.eq(1).val(poundage.toFixed(2));
});
}
$('#price,#amount,#poundage1,#poundage2,#poundage3').change(votecalculator);
</script>