<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CSDN JavaScript Board Testing Page</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
function fmoney(s, n) {
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split(""), r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").join("") + "." + r;
}
</script>
</head>
<body>
<input type="text" id="idtxt" οnkeypress="javascript:alert(fmoney(document.getElementById('idtxt').value,2))"/>
<input type="button" id="btn" οnclick="javascript:alert(fmoney(document.getElementById('idtxt').value,2))" value="test" />
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CSDN JavaScript Board Testing Page</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
function fmoney(s, n) {
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split(""), r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").join("") + "." + r;
}
</script>
</head>
<body>
<input type="text" id="idtxt" οnkeypress="javascript:alert(fmoney(document.getElementById('idtxt').value,2))"/>
<input type="button" id="btn" οnclick="javascript:alert(fmoney(document.getElementById('idtxt').value,2))" value="test" />
</body>
</html>