內容簡介(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" "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 "TEXT-ALIGN:center;height:18px;" type=text name=remLen size=2 maxlength=2 value="160">字。
新聞熱點
疑難解答