JS Statistics text Box remaining can enter the number of words (can be used directly)

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

<title> Show input remaining words </title>

<script>

var maxstrlen=160;

function Q (s) {return document.getElementById (s);}

function Checkword (c) {

Len=maxstrlen;

var str = c.value;

Mylen=getstrleng (str);

var wck=q ("Wordcheck");

if (mylen>len*2) {

C.value=str.substring (0,i+1);

}

else{

wck.innerhtml = Math.floor ((len*2-mylen)/2);

}

}

function Getstrleng (str) {

Mylen = 0;

i=0;

for (;(i<str.length) && (mylen<=maxstrlen*2); i++) {

if (Str.charcodeat (i) >0&&str.charcodeat (i) <128)

mylen++;

Else

mylen+=2;

}

return Mylen;

}

</script>

<body>

<div style= "font-size:16px" >

Control input box character input, calculate the total number of input characters, display the remaining words;<br>

An English character is counted as a char, and a Chinese character is counted as two characters.

</div>

<div>


<textarea onkeyup= "Javascript:checkword (This)," onmousedown= "Javascript:checkword (this);" Name= "Content" style= "Overflow-y:scroll" ></textarea>

</div>

<DIV>

You can also enter <span style= "Font-family:georgia; font-size:26px; "id=" Wordcheck ">160</span> characters </div>

</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.