在需要大量用户输入的系统中,有效地控制用户输入的合法性至关重要。以下例子解决限制用户输入字符个数的问题,以TextBox为例:
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="test" onchange="if(this.value.length>6)this.value=this.value.substr(0,6)" ></asp:TextBox>
</form>
</body>
</html>
或者
</head>
<body>
<form id="form1" runat="server">
<asp:Tex<asp:TextBox runat="server" ID="test2" onkeypress="if(this.value.length>5)return false;" ></asp:TextBox>tBox </form>
</body>
</html>
以上代码可以限制用户输入字符串长度不得超过6,否则无效
浙公网安备 33010602011771号