📄 utility.v1193312278.js
字号:
/*utility.js
* based on mootools v1.0
* wirtten by easy.lv
* some useful extention
*/
/*
* Responsebility : count the num you have inputed or the num you can input now in one input area
*
* count_container_id: your input area id
* showtype: 1:show the num now;2: show the num left to the maxnum
* maxunm:if your showtype=2,this is the max num you can input into the input area
* fill_container_id:the area you want to show the text about the num or the num left
*/
var Count_input_num = function(count_container_id,showtype,maxnum,fill_container_id,ChineseWordsLength,baseon)
{
if(typeof count_container_id == 'string'){
this.ccid = $(count_container_id);
}else{
this.ccid = count_container_id;
}
if(typeof fill_container_id == 'string'){
this.fcid = $(fill_container_id);
}else{
this.fcid = fill_container_id;
}
this.showtype = showtype;
this.maxnum = maxnum;
if(ChineseWordsLength=='')
{
ChineseWordsLength = 2;
}
this.ChineseWordsLength = ChineseWordsLength;
this.ccid.maxlength = this.maxnum;
this.count();
if(baseon = 'prototype')
{
this.ccid.onkeyup = this.count.bindAsEventListener(this);
}else
{
this.ccid.onkeyup = this.count.bindWithEvent(this);
}
};
Count_input_num.prototype.count = function()
{
var replaceword = '';
for(var i=0;i<this.ChineseWordsLength;i++)
{
replaceword = replaceword + '*';
}
this.num = this.ccid.value.replace(/[^\x00-\x80]/ig,replaceword).length;
if(this.showtype == 2)
{
this.left = this.maxnum - this.num;
}
this.showresult();
};
Count_input_num.prototype.showresult = function()
{
if(this.fcid=='')
{
return;
}
if(this.showtype == 1)
{
var str = '现在已经输入'+this.num+'字符';
if(this.ChineseWordsLength>1) str+='(1个汉字等于'+this.ChineseWordsLength+'个字符)';
this.fcid.innerHTML = str;
}
if(this.showtype == 2)
{
if(this.left<0)
{
this.fcid.style.color = "#D50000";
var str = '还可以输入'+this.left+'字符';
if(this.ChineseWordsLength>1) str+='(1个汉字等于'+this.ChineseWordsLength+'个字符)';
str += ',超过最大长度';
this.fcid.innerHTML = str;
}else
{
this.fcid.style.color = "#999999";
var str = '还可以输入'+this.left+'字符';
if(this.ChineseWordsLength>1) str+='(1个汉字等于'+this.ChineseWordsLength+'个字符)';
this.fcid.innerHTML = str;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -