使用JavaScript或jQuery设置文本框的最大长度 [英] Setting maxlength of textbox with JavaScript or jQuery
本文介绍了使用JavaScript或jQuery设置文本框的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用JavaScript或jQuery更改文本框的最大长度:我尝试了以下但它似乎没有帮助:
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);
});
我做错了什么?
推荐答案
不确定你在前几行尝试完成了什么,但你可以试试这个:
Not sure what you are trying to accomplish on your first few lines but you can try this:
$(document).ready(function()
{
$("#ms_num").attr('maxlength','6');
});
这篇关于使用JavaScript或jQuery设置文本框的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文