javascript 限定输入字数
<script type="text/javascript">
function checkMaxlengths(obj, evt, maxLength) {
var event = window.event || evt;
if (event.keyCode != 8) {
if (obj.value.length > maxLength) {
obj.value = obj.value.substring(0, maxLength);
evt.returnValue = false;
}
}
var lbl = document.getElementById("<%=labSep.ClientID%>");
lbl.innerHTML = maxLength - (obj.value.length);
}
</script>
onkeyup="checkMaxlengths(this,event,120)"
<asp:Label ID="labSep" runat="server" Text="120"></asp:Label>
function checkMaxlengths(obj, evt, maxLength) {
var event = window.event || evt;
if (event.keyCode != 8) {
if (obj.value.length > maxLength) {
obj.value = obj.value.substring(0, maxLength);
evt.returnValue = false;
}
}
var lbl = document.getElementById("<%=labSep.ClientID%>");
lbl.innerHTML = maxLength - (obj.value.length);
}
</script>
onkeyup="checkMaxlengths(this,event,120)"
<asp:Label ID="labSep" runat="server" Text="120"></asp:Label>