***综合类***根据面额输入张数,从而算出总数
把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件要完成此效果需要两个步骤
第一步:把如下代码加入到<head>区域中
<script language="javascript">
<!-- begin
function s(num, val) {
amount = num * 1; // amount is the num or nan
sum = (!num ? 0 : num) * val;// the sum for that bill or coin
if (isnan(amount)) { // if the entire is not a number
alert(
"' " + num + " ' is not a valid entry and that field will "
+ "not be included in the total money calculation."
);
return 0;
}
else
return sum; // if it is ok, send sum back
}
function money(form) {
hun = s(form.hun.value, 100); // each amount is the returned value
fif = s(form.fif.value, 50);// for the amount in the s() function
twe = s(form.twe.value, 20);
ten = s(form.ten.value, 10);
fiv = s(form.fiv.value, 5);
two = s(form.two.value, 2);
one = s(form.one.value, 1);
hlf = s(form.hlf.value, .5);
qtr = s(form.qtr.value, .2);
dme = s(form.dme.value, .1);
nck = s(form.nck.value, .05);
sxw = s(form.sxw.value, .02);
pny = s(form.pny.value, .01);
// add up all the amounts
var ttl = hun + fif + twe + ten + fiv + two
+ one + hlf + qtr + dme + nck + sxw + pny;
// rounds total to two decimal places
ttl = "" + ((math.round(ttl * 100)) / 100);
dec1 = ttl.substring(ttl.length-3, ttl.length-2);
dec2 = ttl.substring(ttl.length-2, ttl.length-1);
if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') ttl += "0";
else ttl += ".00";
}
form.total.value = "¥" + ttl; // display total amount
}
//end -->
</script>
第二步:把如下代码加入到<body>区域中
<center>
<form name=coinform>
<table border=1>
<tr>
<td align=center>100元</td>
<td align=center>50元</td>
<td align=center>20元</td>
<td align=center>10元</td>
<td align=center>5元</td>
<td align=center>2元</td>
<td align=center>1元</td>
</tr>
<tr>
<td align=center><input type=text name=hun size=3></td>
<td align=center><input type=text name=fif size=3></td>
<td align=center><input type=text name=twe size=3></td>
<td align=center><input type=text name=ten size=3></td>
<td align=center><input type=text name=fiv size=3></td>
<td align=center><input type=text name=two size=3></td>
<td align=center><input type=text name=one size=3></td>
</tr>
<tr>
<td colspan=6> </td>
</tr>
<tr>
<td> </td>
<td align=center>50分
<td align=center>20分
<td align=center>10分
<td align=center>5分
<td align=center>2分
<td align=center>1分
</tr>
<tr>
<td> </td>
<td align=center><input type=text name=hlf size=3></td>
<td align=center><input type=text name=qtr size=3></td>
<td align=center><input type=text name=dme size=3></td>
<td align=center><input type=text name=nck size=3></td>
<td align=center><input type=text name=sxw size=3></td>
<td align=center><input type=text name=pny size=3></td>
</tr>
<tr>
<td colspan=5 align=center>
<input type=button name=calc value="总数" onclick="javascript:money(this.form)">
<input type=text name=total size=10>
</td>
</tr>
</table>
</form>
</center>
- ------------ -------------------------
拥有三人行论坛管理系列软件,一个人就可以管理一个论坛的更新维 护。还能使您的 论坛有千人在 线的真 实火暴效果 ,让您不在为论坛因没有人气而留不住会员而烦恼 ,使您 的论坛早日成为一流的论坛。详情请登陆网站 :http://www.cnsrx.cn 三人行论坛管理软件,站长 必备的专业好工具。(您使用的是免费版本,购买收费版本后,将不带广告 。业务QQ:2472 16 44985227)
页:
[1]