2010年9月4日 星期六

設定Input只能輸入數值


在Script Tag之中加入限制的方法

<Script>

...

$(function() 
{
$('#InputID').bind('keypress', filterWithOutNumber)
});



//限制只能輸入數值的方法
function filterWithOutNumber(e) 
{
if(e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
return false;
else
return true;
}

...

</Script>

<body>
<Input type="text" id="InputID"></Input>
</body>


沒有留言:

張貼留言