Upv*_*ote 10 javascript jquery
我使用NobleCount计算字符和以下代码:
$('#message').NobleCount('#messageInfo',{
max_chars: getMaxChars(),
on_negative: function(t_obj, char_area, c_settings, char_rem){
}
});
Run Code Online (Sandbox Code Playgroud)
我想要一个像计数短信的功能,如果达到限制,接下来的160个字符是第二个短信,依此类推.我可以使用on_update,on_positive,on_negative和block_negative等参数.
我尝试使用modulo,但它不起作用.有任何想法吗?
Cra*_*een 41
请注意,SMS比您指示的更复杂.
标准的"160字符"SMS使用奇怪的7位编码,涵盖大多数ASCII,一些欧洲口音,misc符号,如€,一些大写希腊字母(看起来不像罗马字符的那些).
如果您的消息使用其他字符,则可以使用UCS-2(如UTF-16但仅限BMP)将其编码为Unicode,限制为70个字符.实际上,本说明书中表示 UCS-2,但表情符号(非BMP Unicode)的可在SMS使得意味着UTF-16被发送时被使用,在这种情况下,每个表情符号必须"用完" 2个字符出来的总共70个的.
但是有些语言可以使用"国家语言转换表",它使用另一种 7位编码.最着名的是土耳其语,还有西班牙语,葡萄牙语和十种印度次大陆语言.这些是标准的新增功能.
即使在7位编码中,一些字符也被"转义",这意味着它们"耗尽"了2个字符.在默认的7位编码中,这些是:{}[]\|^~€.
如果您的消息超过160个字符,它可以使用"连接SMS",但随后会在每个消息中添加一个小标题,这意味着每个段只有153个字符的空间.该标题有两种不同版本,大小不同,因此可能不是153个字符,而是152个(来自内存).类似地,对于Unicode连接的SMS,小标头使每个段有67个字符.
祝你好运!
lon*_*day 26
首先,字符计数非常容易.您只需要length在字符串上使用该属性.要计算所需的SMS消息数量,您需要除以160并向上舍入(因为161个字符需要2条消息).您的代码应该看起来像这样:
HTML:
<textarea name="message" value="" id="message"></textarea>
<p>
<span id="remaining">160 characters remaining</span>
<span id="messages">1 message(s)</span>
</p>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(document).ready(function(){
var $remaining = $('#remaining'),
$messages = $remaining.next();
$('#message').keyup(function(){
var chars = this.value.length,
messages = Math.ceil(chars / 160),
remaining = messages * 160 - (chars % (messages * 160) || messages * 160);
$remaining.text(remaining + ' characters remaining');
$messages.text(messages + ' message(s)');
});
});
Run Code Online (Sandbox Code Playgroud)
sul*_*est 13
这是一个小插件给你.这是我的第一个jQuery插件,我免费提供;)你只需要启动它:
$('#smsText').smsArea();
Run Code Online (Sandbox Code Playgroud)
HTML:
<b id="smsCount"></b> SMS (<b id="smsLength"></b>) Characters left
<textarea id="smsText"></textarea>
Run Code Online (Sandbox Code Playgroud)
Javascript(更新于18.8.2014):
(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));
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/t32h0gj4/1/
注意:有一些基本选项
$('#smsText').smsArea({cut:false}); //Do not cut the SMS
$('#smsText').smsArea({maxSmsNum:2}); //2 SMS Max
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16210 次 |
| 最近记录: |