四舍五入問題!!

在一個輸入框中,如何在onblur事件發生前(焦點離開前),不管輸入數字有多少位小數,但Value值為四舍五入後小數點保留兩位?
---------------------------------------------------------------

1<input name="textfield" onblur="javascript:this.value=parseFloat(this.value).toFixed(2)" onkeyup="this.value=this.value.replace(/[^0-9.]/,'');" type="text"/>

---------------------------------------------------------------

1<input name="textfield" onblur="javascript:this.value=Math.round(parseFloat(this.value)*100)/100" onkeyup="this.value=this.value.replace(/[^0-9.]/,'');" type="text"/>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus