问题描述
- jQuery的问题,啦啦!!!!!!
-
如图片公式那样计算
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>
解决方案二:
$(function(){
$("#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);
});
解决方案三:
至于金额和手续费同时设置就把设置金额的值和设置手续费的值一起调用就行了啊,你说的复杂,其实你这问题很简单
时间: 2025-01-26 17:21:13