DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 新浪微博字數統計 textarea字數統計實現代碼
新浪微博字數統計 textarea字數統計實現代碼
編輯:關於JavaScript     
復制代碼 代碼如下:
/*
* 從新浪微博上抄的
* */
var getLength = (function(){
var trim = function(h) {
try {
return h.replace(/^\s+|\s+$/g, "")
} catch(j) {
return h
}
}
var byteLength = function(b) {
if (typeof b == "undefined") {
return 0
}
var a = b.match(/[^\x00-\x80]/g);
return (b.length + (!a ? 0 : a.length))
};

return function(q, g) {
g = g || {};
g.max = g.max || 140;
g.min = g.min || 41;
g.surl = g.surl || 20;
var p = trim(q).length;
if (p > 0) {
var j = g.min,
s = g.max,
b = g.surl,
n = q;
var r = q.match(/(http|https):\/\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z\$\.\+\!\_\*\(\)\/\,\:;@&=\?~#%]*)*/gi) || [];
var h = 0;
for (var m = 0,
p = r.length; m < p; m++) {
var o = byteLength(r[m]);
if (/^(http:\/\/t.cn)/.test(r[m])) {
continue
} else {
if (/^(http:\/\/)+(weibo.com|weibo.cn)/.test(r[m])) {
h += o <= j ? o: (o <= s ? b: (o - s + b))
} else {
h += o <= s ? b: (o - s + b)
}
}
n = n.replace(r[m], "")
}
return Math.ceil((h + byteLength(n)) / 2)
} else {
return 0
}
}
})();
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved