您的位置:首页 > Web前端 > JavaScript

JS统计还可以输入多少字数

2014-05-27 09:44 148 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<script type="text/javascript" src="../../api/jquery/jquery-1.5.2.min.js"></script>

<SCRIPT language="javascript">

function txtanum() //统计txta的输入字数

{

var maxl = 81;

var num = 80;

var content = $("#txtContent").val();

content.slice(0, maxl);

var nowlength = content.length;

if (nowlength >= 0) {

if (nowlength < num) {

$("#spid").text(num - nowlength);

} else {

$("#spid").text(0);

}

} else {

$("#txtContent").val(content.substring(0, maxl - 1));

}

if (nowlength == 0) {

$("#spid").text(num);

}

if (nowlength > num) {

$("#txtContent").val(content.substring(0, num))

}

}

</script>

</head>

<body> 你还可以输入<span id="spid">80</span>字</div>

<textarea id="txtContent" onkeypress="" class="zhongj_sou_as" tabindex="3" name="txtContent" onkeyup="txtanum()"

runat="server"></textarea></div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: