关于UTF8页面中文COOKIE个人解决办法:
1.使用cgi语言将中文转换成unicode编码,如"\u****";
2.将unicode编码写入cookie;
3.使用js转换此unicode,如:
unescape(CE.cookie.get("***").replace(/\\/g,"%"))
搞定!不知道还有没有更好的解决方案,或者该方法是否存在一些漏洞问题??
			
posted @ 
2010-05-25 13:40 jacklau 阅读(184) | 
评论 (0) | 
编辑 收藏 
		
			
		
			
			关于链接<a>上面直接写javascript事件的问题,今天组内讨论了一下,小写一下:
常见的写法有:
1.<a href="javascript:fun()"></a> //直接在href属性中执行fun事件
2.<a href="javascript:void(0)" onclick = "fun();"></a> //在onclick属性中执行fun事件
3.<a href="#" onclick = "fun();return false;"></a> //href属性指向"#",而onclick事件中return false阻止默认行为
最终投票决定使用第三种方法,前两种方法在IE6都会是gif或其他可以动画效果的东东静止掉。。。具体原因应该是浏览器渲染问题吧,呵呵
第三种方法也有用到针对SEO方面的应用,比如我有一个连接是到一个静态页面a.html,但是由于需求方面的问题需要通过一个cgi再跳转到a.html,如:b.cgi?uri=a.html,这样的写成:<a href="a.html" onclick="window.open('b.cgi?uri=a.html');return false;">XXX</a>表面上可以解决了问题,但是这种算不算是SEO的URL欺骗行为呢?
			
posted @ 
2010-01-26 11:20 jacklau 阅读(395) | 
评论 (0) | 
编辑 收藏 
		
			
		
			
			主要功能:
1.拖动
2.可配置相对位置
3.平滑移动
CE.Tween = {
 plcMove : function(o, a, s, e, callback, speed){
  var sTime = +new Date(), p, speed = speed || 100;
  var iTimer = setInterval(function(){
   p = (+new Date() - sTime) / speed;
   if(p >= 1){
    o.style[a] = e + "px";
    callback && callback.call(o);
    o = null;
    return clearInterval(iTimer);
   }
   o.style[a] = s + (e - s) * ((-Math.cos(p * Math.PI) / 2) + 0.5) + "px";
  }, 10);
 }
};
CE.Util.Drag = {
    dcount : 0,
    dList : {},
    bind : function(c,obj){
        var _this = CE.Util.Drag;
        var _d = obj.d || c;
        if(!_d){return;}
        if(!_d.did){
            _d.did = _this.dcount++;
            _this.dList[_d.did] = _d;
            var _x ,_y,_isdown = false,_scape = null,_p = null;
            _d.style.cursor = "move";
            var down = function(e){
                _isdown = true;
                _p = obj.refer || document.body;
                _x = e.clientX - _d.offsetLeft; //初始坐标
                _y = e.clientY - _d.offsetTop;
                if(null == _scape){
                    _scape = document.createElement("div");
                    _p.appendChild(_scape);
                }
                _scape.style.border = "1px dotted #06459c";
                _scape.style.position = "absolute";
                _scape.style.zIndex = c.style.zIndex + 1 || 1;
                _scape.style.width = c.style.width;
                _scape.style.height = c.style.height;
                _scape.style.left = c.offsetLeft + "px";
                _scape.style.top = c.offsetTop + "px";
                c.style.filter = "Alpha(Opacity=60)";
                c.style.opacity = 0.6;
                if(_scape){
                    CE.Event.addListener(document,"mousemove",move);
                    CE.Event.addListener(document,"mouseup",up);
                    document.onselectstart = function() {return false};
                    if(window.getSelection){ //非ie
                        window.getSelection().removeAllRanges();
                    }
                }
            };
            var move = function(e){
                if(!_isdown){return};
                _scape.style.left = e.clientX - _x + "px";
                _scape.style.top = e.clientY - _y + "px";
            };
            var up = function(){
                _isdown = false;
                if(_scape){
                    if(obj.tween){
                        CE.Tween.plcMove(c,"top",parseInt(c.style.top, 10),_scape.offsetTop);
                        CE.Tween.plcMove(c,"left",parseInt(c.style.left, 10),_scape.offsetLeft);
                    }else{
                        c.style.left = _scape.offsetLeft + "px";
                        c.style.top = _scape.offsetTop + "px";
                    }
                    c.style.filter = "Alpha(Opacity=100)";
                    c.style.opacity = 1;
                    _scape.style.zIndex = c.zIndex - 1 || -1;
                    _p.removeChild(_scape);
                    _p = null;
                    _scape = null;
                    document.onselectstart = function() {return true};
                }
            };
            CE.Event.addListener(_d,"mousedown",down);
        }else{
            for(var item in _this.dList){
                if(_d.did === item.did){
                    return;
                }
            }
        }
    }
};
			posted @ 
2010-01-17 12:16 jacklau 阅读(197) | 
评论 (0) | 
编辑 收藏 
		
			
		
			
			特点:
1.支持fn参数中使用this关键字
2.相同fn绑定无效
缺点:
非ie下不能直接使用匿名函数直接当参数传递,这个谁有比较好的解决办法么?

CE.Event = 
{

    handler : function(e)
{
        e = e || window.event;
        var _fn = "_" + e.type;

        if(this[_fn])
{

            for(var _f in this[_fn])
{
                this[_fn][_f].call(this,e);
            }
        }
    },

    bind : function(obj, act, fn, capture)
{

    if(window.addEventListener)
{
            obj.addEventListener(act,fn,capture || false);

        }else
{
            var _fn = "_" + act;
            act = "on" + act;

            if(!obj[_fn])
{
                obj[_fn] = [];
                obj[act] = CE.Event.handler;

            }else
{

                for(var _f in obj[_fn])
{

                    if(obj[_fn][_f].toString() === fn.toString())
{return};
                }
            }
            obj[_fn][obj[_fn].length] = fn;
        }
    },

    unbind : function(obj, act, fn, capture)
{

        if(window.removeEventListener)
{
            obj.removeEventListener(act,fn,capture || false);

        }else
{
            var _fn = "_" + act;

            if(obj[_fn])
{

                for(var _f in obj[_fn])
{

                    if(obj[_fn][_f].toString() === fn.toString())
{

                        try
{
                            delete obj[_fn][_f];

                        }catch(e)
{
                            obj[_fn][_f] = null;
                        }
                        return;
                    }
                }
            }
        }
    }
}; 
提升了一下执行效率:
CE.Event = {
    ecount : 1,
    handler : function(e){
        e = e || window.event;
        if(this.evns[e.type]){
            for(var evn in this.evns[e.type]){
                this.evns[e.type][evn].call(this,e);
            }
        }
    },
    bind : function(obj, act, fn, capture){
        if(window.addEventListener){
            obj.addEventListener(act,fn,capture || false);
        }else{
            if(!fn.id){fn.id = CE.Event.ecount++};
            if(!obj.evns){obj.evns = {}};
            if(!obj.evns[act]){
                obj.evns[act] = {};
                if(obj["on" + act]){
                    obj.evns[act][0] = obj["on" + act];
                }
            }else{
                for(var evn in obj.evns[act]){
                    if(evn.id === fn.id){return;}
                }
            }
            obj.evns[act][fn.id] = fn;
            obj["on" + act] = CE.Event.handler;
        }
    },
    unbind : function(obj, act, fn, capture){
        if(window.removeEventListener){
            obj.removeEventListener(act,fn,capture || false);
        }else{
            if(obj.evns && obj.evns[act]){
                try{
                    delete obj.evns[act][fn.id];
                }catch(e){
                    obj.evns.act[fn.id] = null;
                }
                return;
            }
        }
    }
};
			posted @ 
2010-01-14 01:17 jacklau 阅读(231) | 
评论 (1) | 
编辑 收藏 
		
			
		
			
			1.匹配电话号码(国内)
   (?:\(?(?:[\+0]?)[0-9]+?[\)?-])?[0-9]{3,4}(?:-?)[0-9]{7,8}(?:(?:-?)[0-9]+)?
   匹配:01012345678,010-12345678,+86-010-12345678,(86)010-1234567,(086)010-12345678 等等
			
posted @ 
2010-01-08 19:03 jacklau 阅读(184) | 
评论 (0) | 
编辑 收藏 
		
			
		
			
			新写了一个兼容ie,ff的Storage类,主要实现:
1.存储,
2.获取,
3.删除,
数据支持字符串/json
以下是源码:
Storage = (function(){
    var isInit = false;
    var obj = null;
    var defDay = 365;
    var isIE = ("\v" == "v");
    var ikey = "Tenpay_Default_Data";
    var domain = document.domain; //或者提取自己框架的
    var initObj = function(){
        if(isIE){
            obj = document.createElement("div");
            obj.id = "Default_JData_id";
            obj.style.behavior = "url('#default#userData')"
            document.body.appendChild(obj);
            isInit = true;
        }
    };
    var setExpire = function(day){
        defDay = day;
    };
    var jsonToStr = function(json){
        var list = [];
        if("string" === typeof(json)) return "\""+ json.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
        if("number" === typeof(json)) return json;
        if("undefined" === typeof(json)) return "undefined";
        if("object" === typeof(json)){
            if(null === json){return null}
            else if("function" === typeof(json.sort)){
                for(var i = 0,len = json.length; i < len; i++){
                    list.push(jsonToStr(json[i]));
                }
                return "["+ list.join() +"]";
            }else{
                for(var i in json){
                    list.push(i + ":" + jsonToStr(json[i]));
                }
                return "{"+ list.join() +"}";
            }
        }
    };
    var strToJson = function(str){
        return eval('('+ str +')');
    };
    var setData = function(name, value, domain_name, key, day){
        ikey = key || ikey;
        domain = domain_name || domain;
        if(!isInit){initObj()};
        if(value instanceof Object){
            value = jsonToStr(value);
        }
        var d = new Date(),exps = (null != day ? day : defDay);
        d.setSeconds(d.getSeconds() + exps * 24 * 3600);
        try{if(isIE){
            obj.load(ikey);
            obj.setAttribute(name, value);
            obj.expires = d.toUTCString();
            obj.save(ikey);
        }else if(window.globalStorage){
             globalStorage[domain][ikey + "__" + name] = value;
             globalStorage[domain][ikey + "__expire"] = d.getTime();
        }}catch(e){}
    };
    var getData = function(name, domain_name, key){
        ikey = key || ikey;
        domain = domain_name || domain;
        if(!isInit){initObj()};
        try{
      if(isIE){
            obj.load(ikey);
            return /^\{.*\}$|^\[.*\]$/.test(obj.getAttribute(name)) ? strToJson(obj.getAttribute(name)) : obj.getAttribute(name);
          }else if(window.globalStorage){
        var now = parseFloat((new Date()).getTime()), exp = parseFloat(globalStorage[domain][ikey + "__expire"]);
        if (exp > now) {
              return /^\{.*\}$|^\[.*\]$/.test(globalStorage[domain][ikey + "__" + name]) ? strToJson(globalStorage[domain][ikey + "__" + name]) : globalStorage[domain][ikey + "__" + name];
        }else {
          delData(name, key);
        }
          }
    }catch(e) {
      //exception
    }
        return "";
    };
    var delData = function(name, domain_name, key){
        ikey = key || ikey;
        domain = domain_name || domain;
        if(!isInit){initObj()};
    try {
        if(isIE){
            obj.load(ikey);
            obj.removeAttribute(name);
            obj.save(ikey);
        }else if(window.globalStorage){
            globalStorage[domain][ikey + "__" + name] = undefined;
            globalStorage[domain].removeItem(ikey + "__" + name);
        }
    }catch (e) {}
    };
    return {
        setExp : setExpire,
        set : setData,
        get : getData,
        del : delData
    };
})();
			posted @ 
2010-01-06 22:28 jacklau 阅读(253) | 
评论 (0) | 
编辑 收藏 
		
			
		
			
			https协议空请求ie下报安全警告,很纠结的问题啊,
比如我使用一个<iframe>,src属性为:about:blank,javascript:void(0),javascript://在ie下都会报安全警告,
后来发现了一个hack,javascript:'',以为终于可以自喜,上线后居然xp sp2又报错了,本来最近老是出错,又出现了这个BUG,真的是要吐血了,没办法还是改回了指向一个空白页面
难道就没有更好的办法了么?
			
posted @ 
2010-01-06 11:01 jacklau 阅读(372) | 
评论 (0) | 
编辑 收藏