1. 程式人生 > >textbox js 只能輸入數字

textbox js 只能輸入數字

<asp:TextBox runat="server" type="text" ID="txtuserName" MaxLength="15" onpaste="return false"

    ​    ​style="ime-mode: disabled" onKeyPress="checkNumeric(value)"  >

</asp:TextBox>


<script type="text/javascript">

    window.onload = function () {

        var items = document.getElementsByName("txtuserName");

        items[0].onkeyup = function () {

            items[0].value = items[0].value.replace(/[^\d]/g, '');

        }

    }

</script>