用到了JQuery。
还有JQuery的插件,下载地址:http://code.google.com/p/jquery-formatcurrency/
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="jquery-1.7.1.min.js"></script>
<script src="jquery.formatCurrency-1.4.0.js"></script>
<script>
$(function(){
var zh = {
symbol: '¥',
positiveFormat: '%s%n',
negativeFormat: '%s-%n',
decimalSymbol: '.',
digitGroupSymbol: ',',
groupDigits: true
};
$("#but").click(function(){
$("#test").formatCurrency(zh);
});
$("#but2").click(function(){
$("#test").toNumber(zh);
});
});
</script>
</head>
<body>
<input type="text" id="test">
<input type="button" value="click me" id="but">
<input type="button" value="click me2" id="but2">
</body>
</html>