<html>
<body>
<form name=form1>
<input name="textfield2" type="text" onKeyUp="value=value.replace(/[^\d]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
</form>
</body>
</html>
代碼說明:
onKeyUp是鍵盤彈起事件。