js限制input的輸入

2021-10-02 02:00:27 字數 879 閱讀 6750

限制只能輸入大於等於0的正整數

onkeyup="value=(value.replace(/\d/g,'')==''?'':parseint(value))"
限制輸入正整數(不包括0)

onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
限制輸入大於等於0的兩位小數

oninput="value= value.match(/\d+(\.\d)?/) ? value.match(/\d+(\.\d)?/)[0] : ''"
element   in-put

/**

* oninput 限制輸入框小數點位數,多出的過濾掉

* @param number

* @param number

* created by preference on 2020/04/10

*/oninput(num, limit)

//第一位不能是.

if (len1 == ".")

//限制只能輸入乙個小數點

if (str.indexof(".") != -1)

} //正則替換

str = str.replace(/[^\d^\.]+/g, '') // 保留數字和小數點

if (limit / 1 === 1) )?.*$/,'$1') // 小數點後只能輸 1 位

} else )?.*$/,'$1') // 小數點後只能輸 2 位

} return str

},

js限制input輸入

1.取消按鈕按下時的虛線框,在input裡新增屬性值 hidefocus 或者 hidefocus true 2.唯讀文字框內容,在input裡新增屬性值 readonly 3.防止退後清空的text文件 可把style內容做做為類引用 4.enter鍵可以讓游標移到下乙個輸入框 5.只能為中文 有...

js限制input輸入

1.取消按鈕按下時的虛線框,在input裡新增屬性值 hidefocus 或者 hidefocus true 2.唯讀文字框內容,在input裡新增屬性值 readonly 3.防止退後清空的text文件 可把style內容做做為類引用 4.enter鍵可以讓游標移到下乙個輸入框 5.只能為中文 有...

js限制input輸入

1.取消按鈕按下時的虛線框,在input裡新增屬性值 hidefocus 或者 hidefocus true 2.唯讀文字框內容,在input裡新增屬性值 readonly 3.防止退後清空的text文件 可把style內容做做為類引用 4.enter鍵可以讓游標移到下乙個輸入框 5.只能為中文 有...