87,919
社区成员
发帖
与我相关
我的任务
分享
<html>
<head> <title>jishu </title>
<script language="javascript">
function check(myObj)//strInput)
{
var num=0;
var reg=/\b/g;
var strInput=myObj.value;
/*
while(reg.exec(strInput))
{
//strInput=RegExp.rightContext;
num++;
}
*/
var arrMatches =strInput.match(reg);
num=arrMatches.length;
document.getElementById('txt').value=num/2;
/*
if(navigator.appName.indexOf("Explorer") >-1)
{
document.getElementById('txt').innerText = num/2;
}
else
{
document.getElementById('txt').textText = num/2;
}
*/
return;
}
</script>
</head>
<body >
<textarea cols="15" rows="25" onkeyup="javascript:check(this);" onblur="javascript:check(this);"></textarea>
<input type="text" value="" id="txt" />
</body>
</html>
<html>
<head> <title>jishu </title>
<script language="javascript">
function check(str)
{
$("show").innerHTML = str.length
}
function $(id)
{
return document.getElementById(id);
}
</script>
</head>
<body >
<textarea id="txt" cols="15" rows="25" onkeyup="check($('txt').value)" onblur="check($('txt').value)"></textarea>
<div id="show"></div>
</body>
</html>