Imitation micro bo 140 characters limit more than red flashing hint JS effect

Source: Internet
Author: User
The code is as follows Copy Code


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;
}

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.