这可能是睡眠不足,但尝试将函数格式化为:
- 字段 2 = 字段 1 * 1.15 返回美元金额
- 字段 3 = 用户定义的整数百分比
- 字段 4 = 字段 3 * 字段 2 返回美元金额
我试图添加 jquery 货币格式,但显然它没有正确链接。我会很感激任何关于我哪里出错的指导 - 我已经研究过这个并且没有理解一些答案。提前感谢您的时间。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.css" />
<style>
.quote {width:600px; font-family:Arial, Helvetica, sans-serif; font-size:14px; padding-top:20px; padding-bottom:20px; font-weight:bold;}
.data {font-family:Arial, Helvetica, sans-serif; font-size:14px; padding-top:20px; padding-left:40px;}
.data1 {font-family:Arial, Helvetica, sans-serif; font-size:14px; padding-top:20px; padding-left:40px; font-weight:bold}
.input {width:10px;}
.label1 {padding-top:5px; padding-bottom:20px; }
.label2 {padding-top:5px; padding-bottom:20px;}
.field {padding-left:75px;}
</style>
<script src="js/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.js">
</script>
<script src="js/jquery.formatCurrency.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function compute() {
var a = $('#a').val(); //field1
var total = a * 1.15; //field2
$('#total').val(total); //field1 * 1.15 = field2
var c = $('#c').val(); //field3 percent defined
var calc = (c /10) * total;
$('#calc').val(calc); //calc field4
var calc2 = (calc + total);
$('#calc2').val(calc2); //calc field5 (field2 + field3)
var calc3 = (total * .20);
$('#calc3').val(calc3); //calc field6 (field2 x 20%)
var calc4 = (total * .80);
$('#calc4').val(calc4); //calc field7 (field2 x 80%)
var d = $('#d').val(); //field8 percent defined
var calc5 = (d /10) * total;
$('#calc5').val(calc5); //calc field9
var calc6 = (a * 1);
$('#calc6').val(calc6); //calc field10
var calc7 = (calc3 - calc4);
$('#calc7').val(calc7); //calc field11
var calc8 = (a * 1);
$('#calc8').val(calc8); //calc field12
var calc9 = (a - calc5);
$('#calc9').val(calc9); //calc field13
}
$('#a, #c, #calc, #calc2, #calc3, #calc4, #calc5, #d, #calc6, #calc7, #calc8, #calc9, #input').change(compute)
$('#input').currency();
});
</script>
</head>
<body>
<div data-role="page" id="irr">
<div data-role="header">
</div>
<div data-role="content">
<div data-role="fieldcontain">
<div class="quote">
<label for="a">Field 1</label>
<input width:"10px" type="number" name="a" id="a" value="" /> </div>
<div class="data1">
<br>
<label for="total"> = Field 2</label>
<input type="text" name="total" id="total" value="" /> </div>
<div class="data">
<label for="c">- Field 3 </label>
<input type="number" name="c" id="c" maxlength="2" value="" />%
Field 4 (<label for="calc"> </label>
<input type="number" name="calc" id="calc" value="" />)</div>
<div class="data1">
<label for="calc2">= Field 5</label>
<input type="number" name="calc2" id="calc2" value="" /></div>
<div class="data">
<label for="calc3">- Field 6 (20%)</label>
<input type="number" name="calc3" id="calc3" value="" /></div>
<div class="data1">
<label for="calc4">= Field 7</label>
<input type="number" name="calc4" id="calc4" value="" /></div>
<div class="data">
<label for="d">- Field 8</label>
<input type="number" name="d" id="d"maxlength="2" value="" />
<label for="calc5"></label>
Field 9 (<input type="number" name="calc5" id="calc5" value="" />)</div>
<div class="data1">
<label for="calc6">= Field 10</label>
<input type="number" name="calc6" id="calc6" value="" />
<label for="calc7">Field 11</label>
<input type="number" name="calc7" id="calc7" value="" /></div>
<div class="data1">
<label for="calc8">Field 12 on</label>
<input type="number" name="calc8" id="calc8" value="" />
<label for="calc9">Field 13</label>
<input type="number" name="calc9" id="calc9" value="" /></div>
</div>
</div>
</div>
</div>
</body>
</html>