html中利用javascript实现文本框字数的动态计算

寻技术 Html/CSS / JS脚本 2023年07月11日 77

将下列代码存为一个htm文件即可.

<script language="javascript">
var cmccCount = 60; unionCount = 60; phsCount = 30; cncCount = -1;
function showcount(obj)
{
 var len = obj.value.length;
 document.all.wordCount.innerText = '当前字符数:'+len;
 if(cmccCount > 0)
  document.all.cmccSeg.innerText = '移动当前分段:'+ Math.floor(len / cmccCount + 1);
 else
  document.all.cmccSeg.innerText = '移动当前分段:-1';  
 if(unionCount > 0)
  document.all.unionSeg.innerText = '联通当前分段:'+ Math.floor(len / unionCount + 1);
 else
  document.all.unionSeg.innerText = '联通当前分段:-1';  
 if(phsCount > 0)
  document.all.phsSeg.innerText = '电信当前分段:'+ Math.floor(len / phsCount + 1);
 else
  document.all.phsSeg.innerText = '电信当前分段:-1';  
 if(cncCount > 0)
  document.all.cncSeg.innerText = '网通当前分段:'+ Math.floor(len / cncCount + 1);
 else
  document.all.cncSeg.innerText = '网通当前分段:-1';  
}
function printResult(obj){ obj.document.execCommand('Print',false); }
</script>

<form>
this is title not to be printed.
<table ><tr><td>

<textarea />
</td></tr>
</table>
and this too.
</form>

关闭

用微信“扫一扫”