Setting maxlength of textbox with JavaScript or jQ

2019-01-11 12:55发布

I want to change the maxlength of a textbox with JavaScript or jQuery: I tried the following but it didn't seem to help:

var a = document.getElementsByTagName('input');
for(var i=0; i<a.length; i++) {
    if((a[i].type!= 'radio')||(a[i].type!= 'checkbox'))
        a[i].maxlength = 5;
}
document.getElementsByTagName('input')[1].maxlength="3";

$().ready(function()
{
    $("#inputID").maxlength(6);
});

What am I doing wrong?

7条回答
手持菜刀,她持情操
2楼-- · 2019-01-11 13:30

How about just maxlength="10"? For example,

<input type="text" maxlength="10">
查看更多
登录 后发表回答