var oH2 = $ ("#spetit_word");/Prompt text var Otextarea = $ ("#p_qa_content");//Input box var Obutton = $ ("#bt-ico");//button Otextarea.live ("KeyUp", function () { Limit (Otextarea, 280, oH2); }) Obutton.live ("click", Function () { if (Font_count < 0 | | | font_count = NULL | | | font_count = 140) { Error (Otextarea); } else { Alert (' Publish success! '); } }); var Font_count; function Wordlength (obj) { var oVal = Obj.val (); var ovallength = 0; Oval.replace (/n*s*/, "") = = "? Ovallength = 0:ovallength = Oval.match (/[^-~]/g) = = null? OVal.length:oVal.length + oval.match (/[^-~]/g). length; Return ovallength } function Error (obj) { var otimer = null; var i = 0; Otimer = setinterval (function () { i++; i = = 5? Clearinterval (Otimer): (i% 2 = 0 obj.css ("Background-color", "#ffffff"): Obj.css ("Background-color", "#ffd4d4")); }, 100); } obj-to check the input box, inow-how many words, tit-prompt box function Limit (obj, inow, tit) { var ovallength = wordlength (obj); Font_count = Math.floor ((inow-ovallength)/2); if (font_count >= 0) { Tit.html ("You can also enter <strong>" + font_count + "</strong> word"); return true; } else { Tit.html ("has exceeded <strong style= ' color:red ' >" + math.abs (font_count) + "</strong> word"); return false; } return font_count; } |