zoukankan      html  css  js  c++  java
  • js 字符串编码与解码

    /**
     * 字符转换为unicode
     */
    function chr2Unicode(str) {
        if ('' != str) {
            var st, t, i;
            st = '';
            for (i = 1; i <= str.length; i++) {
                t = str.charCodeAt(i - 1).toString(16);
                if (t.length < 4)
                    while (t.length < 4)
                        t = '0'.concat(t);
                t = t.slice(2, 4).concat(t.slice(0, 2))
                st = st.concat(t);
            }
            return (st.toUpperCase());
        } else {
            return ('');
        }
    }
    /**
     * unicode转换为字符
     */
    function unicode2Chr(str) {
        if ('' != str) {
            var st, t, i
            st = '';
            for (i = 1; i <= str.length / 4; i++) {
                t = str.slice(4 * i - 4, 4 * i - 2);
                t = str.slice(4 * i - 2, 4 * i).concat(t);
                st = st.concat('%u').concat(t);
            }
            st = unescape(st);
            return (st);
        } else
            return ('');
    }

  • 相关阅读:
    Element Form表单验证
    layui table中记住当前页
    Mysql定时任务
    Mysql存储过程
    StringRedisTemplate与redistemplate
    vue路由传值
    背景色渐变(兼容各浏览器)
    用onclick点击框架跳转
    美化滚动条
    图片无缝滚动
  • 原文地址:https://www.cnblogs.com/zdlblogs/p/6297494.html
Copyright © 2011-2022 走看看