//-------------------------------------------------------code---------------------------------------------------------------
<input type="text" onkeypress="javascript:KeyPress(this);">
<script>
function KeyPress(objTR)
{
var txtval=objTR.value;
var key = event.keyCode;
if((key < 48||key > 57)&&key != 46)
{
event.keyCode = 0;
}
else
{
if(key == 46)
{
if(txtval.indexOf(".") != -1||txtval.length == 0)
event.keyCode = 0;
}
}
}
</script>
//-------------------------------------------------------code---------------------------------------------------------------
but Firebox show mesge error
Firefox will show "var key = event.keyCode;" error ,Change another one
但是用火狐會顯示 "var key = event.keyCode;" 這行錯誤
所以改另用一個方法
//-------------------------------------------------------code---------------------------------------------------------------<input type="text" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" >
//-------------------------------------------------------code---------------------------------------------------------------
Direct use of regularization
直接使用正規化
沒有留言:
張貼留言