JS 货币并格式化判断

发布时间:2008年09月27日      浏览次数:1108 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
function checkMoney(obj){
var tempValue=obj.value.replace(/(^\s+)|(\s+$)/g,'').replace('¥','');
if(!tempValue){return}
if(/^-?\d+(\.\d+)?$/.test(tempValue)){
obj.value="¥"+parseFloat(tempValue).toFixed(2);
}else{
alert('请输入合法的货币值!');
return
}
}
//-->
</script>
<input type="text" onchange="checkMoney(this)" size="20">
</body>
</html>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!