1,html頁面有以下文本:
& ltinput id =“groupid text“type =“text“style =“width:100 px;”maxlength =“6“/& gt。& lt/TD & gt;
2.使用js限制最大輸入長度的腳本如下:
$(函數)
$(‘# groupid text‘)。開?{‘輸入‘,函數(e)?}?
If(this . value . length = = = 6){//如果輸入長度等於6,則輸入被禁用}?
$(‘input【type =“submit“】‘)。prop('disabled ',false);
不然呢?
$(‘input【type =“submit“】‘)。prop('disabled ',true);
Js將文本框輸入的長度限制為18個字符,只能是數字和字母。如果輸入字符超過18個字符,則不能再輸入。
這可以在沒有JS的情況下實現,使用輸入文本標簽的maxlength屬性。?代碼如下:
& lt輸入?type =“text“?maxlength =“18“?/& gt;
只需在maxlength屬性後設置需要限制的字段的最大長度。