1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > input 和 textarea 输入框最大文字限制的jquery插件【jquery】

input 和 textarea 输入框最大文字限制的jquery插件【jquery】

时间:2023-05-27 07:02:52

相关推荐

input 和 textarea 输入框最大文字限制的jquery插件【jquery】

web前端|js教程

输入框,最大文字

web前端-js教程

.net档案管理系统源码,vscode全部格式化,Ubuntu日程弹窗,tomcat安装哪个文件,数据爬虫 服务,php统计字符串的长度,关键词排名郑州seo优化,制图网站源码,物流公司网页模板lzw

/* input 和 textarea 最大文字限定插件

* 修改版, 一个中文表示1一个字, 一个英文半个字;

* TextLimit - jQuery plugin for counting and limiting characters for input and textarea fields

*

* pass -1 as speed if you don want the char-deletion effect. (don just put 0)

* Example: jQuery("Textarea").textlimit(span.counter,256)

*

* $Version: .07.25 +r2

* Copyright (c) Yair Even-Or

* vsync.design@

*/

python小项目源码,ubuntu记录登录信息,tomcat8 64位,家里常见爬虫,武汉php培训老师招聘,睢宁网站seolzw

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 ackspace 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 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);

物业管理系统完整版源码,学vscode的专业,ubuntu英文读音,tomcat 文件过大,sqlite查询记录个数据,win10电脑用爬虫封号,php整站程序,开封seo优化有哪些,jsp网站模板样式,html中文网页模板下载,免费微信网站模板下载lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。