首先,全段滥用该段落元素<p>
。相反,使用folling:
HTML
<div id="subtotal-and-taxes">
<var id="subtotal">15000</var>
<var id="tax">10</var> // In percentage
<var id="discount">1000</var>
<var id="grandtotal"></var> // Grandtotal will be calculated and displayed here using jquery
<!-- or use span elements -->
</div>
CSS
#subtotal-and-taxes var {
display:block
margin-top:5px;
margin-bottom:5px;
}
接下来,你可以使用jQuery来获取这些元素的引用,并与html()
功能读取其内容:
var subtotal = $("#subtotal-and-taxes #subtotal").html();
var tax = $("#subtotal-and-taxes #tax").html();
var discount = $("#subtotal-and-taxes #discount").html();
然后使用非jQuery JavaScript来计算grandtotal
。不幸的是,你的等式有点令人困惑,所以我不会为你拼出来。
您提供的等式有点令人困惑。谨慎地阐述一下它? – 2010-08-17 21:06:47