内容简介(smalltext)加输入字数统计

方法1、统计输入字符数

smalltext添加一个js来提示及统计已输入的字数

把以下smalltext字段的输入的html表单

<textarea name=”smalltext” cols=”80″ rows=”10″ id=”smalltext”><?=$ecmsfirstpost==1?””:ehtmlspecialchars(stripSlashes($r[smalltext]))?></textarea>

替换为

<script language=”javascript”>

function countChar(textareaNamezzjs,spanName){

document.getElementById(spanName).innerHTML=document.getElementById(textareaNamezzjs).value.length;

}

</script>

已经输入<span id=”counter” style=”color:#ff0000″>0</span>字<br>

<textarea id=”smalltext” name=”smalltext” cols=”80″ rows=”10″ onkeydown=”countChar(‘smalltext’,’counter’);” onkeyup=”countChar(‘smalltext’,’counter’);”><?=$ecmsfirstpost==1?””:ehtmlspecialchars(stripSlashes($r[smalltext]))?></textarea>

———————————————————————————————————

方法2、统计输入字符数并限制数量

把以下smalltext字段的输入的html表单

<textarea name=”smalltext” cols=”80″ rows=”10″ id=”smalltext”><?=$ecmsfirstpost==1?””:ehtmlspecialchars(stripSlashes($r[smalltext]))?></textarea>

替换为

<SCRIPT LANGUAGE=”JavaScript”>

<!–//

function textCounter(field, countfield, maxlimit)

{

if (field.value.length > maxlimit)

field.value = field.value.substring(0, maxlimit);

else

countfield.value = maxlimit – field.value.length;

}

//–>

</SCRIPT>

<textarea name=”smalltext” cols=”80″ rows=”10″ id=”smalltext” onMouseOver=”textCounter(this.form.smalltext,this.form.remLen,160);”

onKeyUp=”textCounter(this.form.smalltext,this.form.remLen,160);”><?=$ecmsfirstpost==1?””:ehtmlspecialchars(stripSlashes($r[smalltext]))?></textarea> <FONT color=#999999>还能输入<input readonly style=”TEXT-ALIGN:center;height:18px;” type=text name=remLen size=2 maxlength=2 value=”160″>字。