获取中英文统一的长度

//将中文字符的长度转换为英文字符的长度
function utf16to8(str) {
	//去除左右空格
		str=str.replace(/\\r/g,"\r");
		str=str.replace(/\\n/g,"\n");
        var out, i, len, c;
        out = "";
        len = str.length;
        for(i = 0; i < len; i++) {
			c = str.charCodeAt(i);
			if ((c >= 0x0001) && (c <= 0x007F)) {
				out += str.charAt(i);
				//alert("1---"+out+"---"+out.length);
			} else if (c > 0x07FF) {
				out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
				out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
				out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
				//alert("2---"+out+"---"+out.length);
			} else {
				out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
				out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
				//alert("3---"+out+"---"+out.length);
			}
        }
        return out;
}

使用方法:utf16to8(obj.val()).length

  • Tags:

介绍

MSClass,是一款通用不间断滚动JS封装类,几乎支持目前所有流行风格的图片或文字的滚动/切入/渐显等效果,同时支持横向/竖向/连续/间断/缓动等多种形式。

入门

想要使用这款组件,需要页面引入 MSClass.js 核心文件,该文件在您的HTML文档<head>标签之内。

<script type="text/javascript" src="/path/MSClass.js"></script>

More

  • Tags:


提供UTF-8和GBK两种编码
预览地址:点击此处查看效果 More

  • Tags:

图片滚动效果/按钮控制左右滚动

查看演示 More

  • Tags:

支持图片的渐隐渐现Title效果

查看演示 More

  • Tags:


谷歌中国首页的动画导航效果
查看演示 More

  • Tags:


Flash焦点图片新闻轮播效果(4张图片)
查看演示 More

  • Tags:


色彩斑斓的Flash广告轮换效果
查看演示 More

  • Tags: