随笔 - 11  文章 - 3  trackbacks - 0
<2010年1月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

关于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 阅读(172) | 评论 (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 阅读(382) | 评论 (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 阅读(184) | 评论 (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 阅读(218) | 评论 (1)编辑 收藏