导航
关闭

狼王King

当前位置:首页 > 网络教程 - 正文

帝国CMS内容简介(smalltext标签)增加输入字数统计

  人参与 |更新时间: 2020年01月15日 16:36

帝国CMS内容简介(smalltext标签)增加输入字数统计

方法一、统计输入字符数

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>

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

把以下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">字。

编辑:狼王(微信/QQ:1574808)

来源:狼王King(微信/QQ:1574808),欢迎分享!

本文链接:https://www.iwolfking.com/jiaocheng/162.html

评论专区

留言与评论(共有 0 条评论)
表情:   
验证码: