最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

input 和 textarea 輸入框最大文字限制的jquery插件

 更新時間:2011年10月27日 23:20:58   作者:  
input 和 textarea 輸入框最大文字限制的jquery插件,需要的朋友可以參考下。
復制代碼 代碼如下:

/* input 和 textarea 最大文字限定插件
* 修改版, 一個中文表示1一個字, 一個英文半個字;
* TextLimit - jQuery plugin for counting and limiting characters for input and textarea fields
*
* pass '-1' as speed if you don't want the char-deletion effect. (don't just put 0)
* Example: jQuery("Textarea").textlimit('span.counter',256)
*
* $Version: 2009.07.25 +r2
* Copyright (c) 2009 Yair Even-Or
* vsync.design@gmail.com
*/

String.prototype.getBytes = function () {
var cArr = this.match(/[^\x00-\xff]/ig);
return this.length + (cArr == null ? 0 : cArr.length);
};
(function(jQuery) {
jQuery.fn.textlimit=function(counter_el, thelimit, speed) {
var charDelSpeed = speed || 15;
var toggleCharDel = speed != -1;
var toggleTrim = true;
var that = this[0];
var isCtrl = false;
updateCounter();
function updateCounter(){
if(typeof that == "object")
jQuery(counter_el).text(thelimit - Math.ceil(that.value.getBytes()/2));
};
this.keydown (function(e){
if(e.which == 17) isCtrl = true;
var ctrl_a = (e.which == 65 && isCtrl == true) ? true : false; // detect and allow CTRL + A selects all.
var ctrl_v = (e.which == 86 && isCtrl == true) ? true : false; // detect and allow CTRL + V paste.
// 8 is 'backspace' and 46 is 'delete'
if( this.value.length >= thelimit && e.which != '8' && e.which != '46' && ctrl_a == false && ctrl_v == false)
e.preventDefault();
})
.keyup (function(e){
updateCounter();
if(e.which == 17)
isCtrl=false;
if( this.value.length >= thelimit && toggleTrim ){
if(toggleCharDel){
// first, trim the text a bit so the char trimming won't take forever
// Also check if there are more than 10 extra chars, then trim. just in case.
if ( (this.value.length - thelimit) > 10 )
that.value = that.value.substr(0,thelimit+100);
var init = setInterval
(
function(){
if( that.value.length <= thelimit ){
init = clearInterval(init); updateCounter()
}
else{
// deleting extra chars (one by one)
that.value = that.value.substring(0,that.value.length-1); jQuery(counter_el).text(Math.ceil(that.value.getBytes()/2));
}
} ,charDelSpeed
);
}
else this.value = that.value.substr(0,thelimit);
}
});
};
})(jQuery);

相關文章

最新評論

长岛县| 永丰县| 丰都县| 曲周县| 太白县| 疏勒县| 临武县| 岳普湖县| 温泉县| 普宁市| 凉山| 滕州市| 元朗区| 佛坪县| 库伦旗| 张家港市| 古田县| 青神县| 定陶县| 师宗县| 太原市| 牡丹江市| 金门县| 静乐县| 英超| 土默特左旗| 神池县| 金溪县| 绩溪县| 库车县| 维西| 商丘市| 延津县| 临清市| 广丰县| 乐东| 五家渠市| 京山县| 南安市| 玛沁县| 崇左市|