Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1086239
  • 博文数量: 143
  • 博客积分: 969
  • 博客等级: 准尉
  • 技术积分: 1765
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-30 12:09
文章分类

全部博文(143)

文章存档

2023年(4)

2021年(2)

2020年(4)

2019年(4)

2018年(33)

2017年(6)

2016年(13)

2014年(7)

2013年(23)

2012年(33)

2011年(14)

我的朋友

分类: 系统运维

2011-08-03 08:40:41

function GetStrLength(data)
{
var charCount = 0;
for(var i =0; i
{
var str=data.charAt(i);
 
//if(/[-A-Z|a-z|0-9]/g.test(str))
if(/[u00-uFF]/g.test(str))
 {
  charCount++;
 }
 else
 {
  charCount+=2;
}
}
return charCount;
}
function GetStrType(data)
{
var charCount = 0;
var chineseCount = 0;
var strType = 0;
for(var i =0; i
{
var str=data.charAt(i);
 if(/[-A-Z|a-z|0-9]/g.test(str))
 {
  charCount++;
 }
 else
 {
  chineseCount++;
}
}
if(chineseCount !=0 && charCount == 0)
{
 strType = 1; //纯汉字
}
else if(charCount !=0 && chineseCount == 0)
{
strType = 2; //纯数字或者字符
}
return strType;
}
function GetStrData(data, len)
{
var charCount = 0;
var strchar="";
for(var i =0; i
{
var str=data.charAt(i);
strchar =strchar+str;
//if(/[-A-Z|a-z|0-9]/g.test(str))
if(/[u00-uFF]/g.test(str))
 {
  charCount++;
 }
 else
 {
  charCount = charCount + 2;
}
if(len - charCount <1)
{
 break; 
}
}
return strchar;
}

function SetSignature(newSignature)
{
var signature = document.getElementById('signature');
signature.setAttribute('title', newSignature);
var str= new String(newSignature);
 var strText;
 var strLen = 34;
    if(GetStrType(str)== 1)
    {
      strLen = 38;
    }
  
    var tmpLen = GetStrLength(str);
if(tmpLen > strLen)
{
var strtemp = GetStrData(str, strLen);
 strText= strtemp+"...";
}
else
{
strText = newSignature;
}  
    signature.innerText = strText;
  // signature.innerText = (newSignature.length > 20) ? newSignature.substr(0, 20) + "..." : newSignature;
}


阅读(1755) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~