php随笔7-thinkphp OA系统 JS 文本框输入实时控制字数

JS:

//多行文本输入框剩余字数计算
function checkMaxInput(obj, maxLen) {
if (obj == null || obj == undefined || obj == "") {
return;
}
/*if (maxLen == null || maxLen == undefined || maxLen == "") {
maxLen = 250;
}*/ /* var strResult;
var $obj = $(obj);
var newid = $obj.attr("id") + 'msg';*/ $('#number').show(); if (obj.value.length > maxLen) { //如果输入的字数超过了限制
obj.value = obj.value.substring(0, maxLen); //就去掉多余的字
document.getElementById("msg").innerHTML ="剩"+(maxLen - obj.value.length).toString()+"字";
//strResult = '<a><span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span></a>'; //计算并显示剩余字数
}
else {
//strResult = '<a><span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span></a>'; //计算并显示剩余字数
document.getElementById("msg").innerHTML =(maxLen - obj.value.length).toString();
} /* var $msg = $("#" + newid);
if ($msg.length == 0) {
$obj.after(strResult);
}
else {
$msg.html(strResult);
}*/
} //清空剩除字数提醒信息
function resetMaxmsg() {
$('#number').hide();
}
<textarea name="remarks" style="background-color:#CDFF9A;height:285px;width:165px;resize:none;" onkeydown="checkMaxInput(this,120)"
onkeyup="checkMaxInput(this,120)" onfocus="checkMaxInput(this,120)" onblur="checkMaxInput(this,120);resetMaxmsg()"></textarea> <div style="position:absolute;top:200px;left:250px"><a style="display:none" id="number">剩(<span id="msg">120</span>)字</a></div>

效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAB2CAIAAAD9fTkHAAAFNUlEQVR4nO3bMZLaWACE4XcnTuCUjIxsMu4z6SY+hUOqnLs2nCuQUxwABxICREs8MQi63P/UH+z22Azs6rMA4bJYFCJ6Y++/B0Thvf8eEIWn1598xXz9/vPr7UdheHp994HB14u+fv/5td/v334UhqfX5v/Q/8f/6N9uv9+D8O3pFYQhgdAhvYIwJBA6pFcQhgRCh/QKwpBA6JBeQRgSCB3SK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CrstvniuNvzEy6M92j40xIczUN4bIcN+XrdIli1x3H878mHPvYyglJ+1vGL1Fc/IhaVCCkWZuAcNke2efrhCd7E94dHT47DX0eYHvBoN/p1sTlhJELfVOv8oGQZq0W4fJ8qrm6WL8UF+j0wXrvUP4Owr7Dmg+mjV+Ov3ns8701CsL0KhFu1+ejVnxi5lSDcOhgrX9GOmu1z0Wv5c96t0EY3XM+tjb6wetHAMzW5NPgSwJhdK/+S73zv766L3DOvxkIQpocf7PeIb2CMCQQOqRXEIYEQof0CsKQQOiQXkEYEggd0isIQwKhQ3oFYUggdEivIAwJhA7pFYQhgdAhvYIwJBA6pFcQhgRCh/QKwpBA6JBeQRgSCB3SKwhDAqFDegVhSCB0SK8gDAmEDukVhCGB0CG9gjAkEDqkVxCGBEKH9ArCkEDokF5BGBIIHdIrCEMCoUN6BWFIIHRIryAMCYQO/QUnV32Ji/7KewAAAABJRU5ErkJggg==" alt="" />

上一篇:ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint......


下一篇:开启Java博客