87,907
社区成员
发帖
与我相关
我的任务
分享
<style>
input {width:80px; text-align:right;}
</style>
<TABLE>
<TR>
<th>单价</th>
<th>数量</th>
<th>小计</th>
</TR>
<TR>
<td><input type="text" id="saleprice1" name="saleprice" value="5.5" disabled></td>
<td><input type="text" id="count1" name="count" value="1" onchange="sum(this)"></td>
<td><input type="text" id="total1" name="total" disabled></td>
</TR>
<TR>
<td><input type="text" id="saleprice2" name="saleprice" value="2" disabled></td>
<td><input type="text" id="count2" name="count" value="1" onchange="sum(this)"></td>
<td><input type="text" id="total2" name="total" disabled></td>
</TR>
<TR>
<td colspan="2" align="center">总价是</td>
<td><input type="text" id="alltotal" name="alltotal" disabled></TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
init();
//初始化
function init(){
for (var i=0; i<document.getElementsByName("count").length; i++){
sum(document.getElementsByName("count")[i]);
}
all();
}
function sum(obj){
var pri = obj.parentElement.previousSibling.childNodes[0].value;
var tot = obj.parentElement.nextSibling.childNodes[0];
tot.value = parseFloat(pri) * parseInt(obj.value,10);
all();
}
//算总价
function all() {
var alltot = 0;
for (var i=0; i<document.getElementsByName("total").length; i++){
alltot += parseFloat(document.getElementsByName("total")[i].value);
}
document.getElementById("alltotal").value = alltot;
}
//-->
</SCRIPT>
<TABLE id="tab1" border="1" bordercolor="#CCCCCC" style="border-collapse:collapse;">
<TR bgcolor="#FFEEDD">
<td>
<input type="text" id="saleprice" name="saleprice" value="15"><br>
</td>
<td>
<input type="text" id="count" size="5" name="count" value="1" onchange="calc(this);"><br>
</td>
<td>
<input type="text" id="total" size="5" name="total "><br>
</td>
</TR>
<TR bgcolor="#FFEEDD">
<td>
<input type="text" id="saleprice" name="saleprice" value="25"><br>
</td>
<td>
<input type="text" id="count" size="5" name="count" value="1" onchange="calc(this);"><br>
</td>
<td>
<input type="text" id="total" size="5" name="total "><br>
</td>
</TR>
</TABLE>
<input type="text" id="alltotal" name="alltotal" onblur="">
<BODY>
<SCRIPT LANGUAGE="JavaScript">
function calc(o){
var tab = document.getElementById("tab1");
var i=o.parentNode.parentNode.rowIndex;
document.getElementsByName("total")[i].value=
document.getElementsByName("saleprice")[i].value*
document.getElementsByName("count")[i].value;
document.getElementsByName("alltotal")[0].value=0
for(var r=0;r<tab.rows.length;r++)
document.getElementsByName("alltotal")[0].value=
parseInt(document.getElementsByName("alltotal")[0].value,10)+
parseInt(document.getElementsByName("total")[r].value||0)
}
</SCRIPT>
单件销售额<input type="text" id="count" size="5" name="count" value="100元">
输入你要买的件数<input type="text" id="total" size="5" name="total" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
小计总价 是<input type="text" id="alltotal" name="alltotal" onfocus="showprice();" />
<script>
function showprice(){
var price = document.getElementById("count");
var count = document.getElementById("total");
var alltotal = document.getElementById('alltotal');
alltotal.value = parseInt(price.value,10) * parseInt(count.value,10)+'元' ;
}