Js:
//calculation of remaining words in multi-line text input box functioncheckmaxinput (obj, maxlen) {if(obj = =NULL|| obj = = Undefined | | obj = = "") { return; }/ *if (MaxLen = = NULL | | maxlen = = Undefined | | maxlen = = "") {maxlen = 250; } */ /*var strresult; var $obj = $ (obj); var newid = $obj. attr ("id") + ' msg ';*/ $(' #number '). Show (); if(Obj.value.length > MaxLen) {//if the number of words entered exceeds the limitObj.value = obj.value.substring (0, MaxLen);//just remove the extra words.document.getElementById ("msg"). InnerHTML = "Left" + (maxlen-obj.value.length). toString () + "word"; //strresult = ' <a><span id= ' + newid + ' "class=\ ' max_msg\ ' ><br/> Left (' + (maxlen-obj.value.length) + ') word </span></a> '; Calculate and display the remaining words } Else { //strresult = ' <a><span id= ' + newid + ' "class=\ ' max_msg\ ' ><br/> Left (' + (maxlen-obj.value.length) + ') word </span></a> '; Calculate and display the remaining wordsdocument.getElementById ("msg"). InnerHTML = (MaxLen-obj.value.length). toString (); } /*var $msg = $ ("#" + newid); if ($msg. length = = 0) {$obj. After (strresult); } else {$msg. html (strresult); }*/ } //Erase the left Word reminder message functionresetmaxmsg () {$ (' #number '). Hide (); }
<textareaname= "Remarks"style= "Background-color: #CDFF9A; height:285px;width:165px;resize:none;"onkeydown= "Checkmaxinput (this,120)"onkeyup= "Checkmaxinput (this,120)"onfocus= "Checkmaxinput (this,120)"onblur= "Checkmaxinput (this,120); Resetmaxmsg ()"></textarea><Divstyle= "position:absolute;top:200px;left:250px"><astyle= "Display:none"ID= "Number">Left<spanID= "MSG">120</span>) word</a></Div>
Effect:
PHP essay 7-thinkphp OA system JS text box input real-time control word count