87,910
社区成员
发帖
与我相关
我的任务
分享
function CountText(source) {
var currentValueLength;
var maxLength;
var objSource = document.getElementById(source);
if (event.keyCode == 8 || event.keyCode ==13) {
//// alert(objSource.value.lastIndexOf("\n\n"));
//// alert(objSource.value.substring(objSource.value.length - 2));
//// alert(objSource.value.substring(objSource.value.length - 1));
if (event.keyCode == 13 && objSource.value.lastIndexOf("\n")>0) {
objSource.value = objSource.value.substring(0, objSource.value.lastIndexOf("\n") - 1);
}
}
else {
if (null != objSource) {
maxLength = 11;
currentValueLength = objSource.value.length;
var tempLength = objSource.value.length + 2;
if (tempLength > 1 && tempLength % 13 == 0) {
//alert(objSource.value);
objSource.value += "\n";
objSource.value = objSource.value.substring(0, objSource.value.lastIndexOf("\n") - 1);
}
}
}
}
写了这么个,输入的时候会自己换行,但是,输入11个数,按enter的时候中间会空一行