使 html input 標籤只能輸入數字

其中,使用了JS技術,此時,input 框只接受數字鍵,其餘按鍵均不起做用
<script type="text/javascript">
    function IsNum(ev) {
        var key = window.event ? ev.keyCode : ev.which;
        if (((key >= 48) && (key <= 57)) || k === 8 || k === 0) {
        } else {
            if (window.event) {
                window.event.returnValue = false;
            }
            else {
                ev.preventDefault(); //for firefox 
            }
        }
    }
</script>

<input style="IME-MODE: disabled;" value="1" name="num" onkeypress = "return IsNum(event)">
相關文章
相關標籤/搜索