<BODY>
<script language=javascript>
window.onbeforeunload = function(){
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY < 0 || window.event.altKey)
{
alert("是关闭而非刷新");
window.event.returnValue = "是否关闭?";
}else{
alert("是刷新而非关闭");
}
}
function commafy(num){
num = num+"";
var re=/(-?/d+)(/d{3})/
while(re.test(num)){
num=num.replace(re,"$1,$2")
}
return num;
}
</script>
<input type=button value="commafy" onclick="alert(commafy(1234532但是说到底是多少多少67000.01))">
<input type= "text">
<input type= "text " style= "text-align: right; " onfocus= "this.value =this.value.replace(/,/gi,'')" onblur= "this.value=commafy(this.value);"/>
</BODY>
本文介绍了一种使用JavaScript实现数字格式化的简单方法,并通过一个具体的实例展示了如何在网页中应用该方法。同时,文章还探讨了如何利用JavaScript监听并区分浏览器的关闭和刷新事件。

被折叠的 条评论
为什么被折叠?



