-4
如何使用jquery創建n個短信計數?SMS字符數
像這個代碼只有3短信計數。我需要使用像這個相同的代碼N個短信計數。 怎麼辦?
$('#smsText').smsArea();
的HTML:
<b id="smsCount"></b> SMS (<b id="smsLength"></b>) Characters left
<textarea id="smsText"></textarea>
(function($){
$.fn.smsArea = function(options){
var
e = this,
cutStrLength = 0,
s = $.extend({
cut: true,
maxSmsNum: 3,
interval: 400,
counters: {
message: $('#smsCount'),
character: $('#smsLength')
},
lengths: {
ascii: [160, 306, 459],
unicode: [70, 134, 201]
}
}, options);
e.keyup(function(){
clearTimeout(this.timeout);
this.timeout = setTimeout(function(){
var
smsType,
smsLength = 0,
smsCount = -1,
charsLeft = 0,
text = e.val(),
isUnicode = false;
for(var charPos = 0; charPos < text.length; charPos++){
switch(text[charPos]){
case "\n":
case "[":
case "]":
case "\\":
case "^":
case "{":
case "}":
case "|":
case "€":
smsLength += 2;
break;
default:
smsLength += 1;
}
if(text.charCodeAt(charPos) > 127 && text[charPos] != "€") isUnicode = true;
}
if(isUnicode){
smsType = s.lengths.unicode;
}else{
smsType = s.lengths.ascii;
}
for(var sCount = 0; sCount < s.maxSmsNum; sCount++){
cutStrLength = smsType[sCount];
if(smsLength <= smsType[sCount]){
smsCount = sCount + 1;
charsLeft = smsType[sCount] - smsLength;
break
}
}
if(s.cut) e.val(text.substring(0, cutStrLength));
smsCount == -1 && (smsCount = s.maxSmsNum, charsLeft = 0);
s.counters.message.html(smsCount);
s.counters.character.html(charsLeft);
}, s.interval)
}).keyup()
}}(jQuery));
我試過短信字符數。但是這個代碼只有3個數字。我需要n個短信計數。就像創建超過100或200個短信一樣。如果有人知道手段發送查詢。
您必須向我們展示您嘗試過的方式以幫助您解決問題。 – avcajaraville 2014-09-25 12:10:41