论坛首页 Web前端技术论坛

用prototype和scriptaculousus美化了文件的上传(改进了)

浏览 4040 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-08-01  
这个代码中有点问题,望一下
<html>
<head>
<script src='prototype.js'></script>
<script src='effects.js'></script>
<script language="javascript" type="text/javascript">
    var Upload = Class.create();
    Object.extend(Upload.prototype,{
        initialize : function(){
           $("bxAtt2").innerHTML = "<input type='file' name='file1' size=1  hidefocus  style='cursor:hand'/>"
           $$('#bxAtt2 input')[0].onchange = this.file_change.bind(this,$$('#bxAtt2 input')[0]);   
        },
        file_change : function(f){
            var _name = f.value.replace(/\\/g,"/").replace(/(.*\/)(.*)/,"$2");
            var _n = document.createElement("nobr");
            _n.style.cssText = "float:left;margin-right:6;padding-top:3;color:darkgreen;font-size:12px";
            _n.appendChild(document.createTextNode(_name));
            var _font = document.createElement("font");
            _font.style.cssText = "color:red;font-weight:bold;cursor:hand";
            _font.appendChild(document.createTextNode(unescape("%d7")));
             _font.onclick = this.remove_file.bind(this,_n);
            _n.appendChild(_font);
            f.style.display = 'none';
            _n.appendChild(f);
            $("bxAttList").insertBefore(_n,$("bxAtt"));
            new Effect.BlindDown(_n,{
                    scaleX: true,
                    scaleY : false,
                    afterSetup: function(effect) {
                        effect.element.makeClipping().setStyle({width: '0px'}).show(); 
                    }
            });
            this.initialize()
        },
        remove_file : function(obj){
           new Effect.BlindUp(obj,{
                scaleX: true,
                scaleY : false
           });
           $('bxAttList').removeChild(obj);//这里如果我加入这句回退的效果就没了,可不加又不行,不知该怎样实现,即实现回退效果又能把该节点删除
        }
    })
    Event.observe(window,'load',function(){new Upload('bxAttList')})
</script>
</head>

<body>
<div id=bxAttList>
    <div id=bxAtt style="float:left;width:60;position:absolute">
        <span id=bxAtt1 style='position:absolute;padding-top:3;cursor:hand;font-family:宋体;font-size:12px'>添加附件</span>
        <span id=bxAtt2 style='position:absolute;left:-10px;width:70;overflow:hidden;filter:alpha(opacity=20);-moz-opacity:0;'></span>
    </div>
</div>
</body>
</html>
   发表时间:2007-08-01  
我自己搞定了,看了他的源码才知道,他有个 afterFinishInternal方法,可以实现特效完后的操作
重写后的remove_file方法
  remove_file : function(obj){
           new Effect.BlindUp(obj,{
                scaleX: true,
                scaleY : false,
                afterFinishInternal: function(effect) {
                    $('bxAttList').removeChild(effect.element);
                } 
           });
        }

谁有他的api呀,共享一下,我上他的官方网站,找了半天没找到
0 请登录后投票
   发表时间:2007-08-16  
我又改进了增加了,限制文件的数量,不能上传相同的文件
// JavaScript Document
    var Upload = Class.create();
    Object.extend(Upload.prototype,{
        initialize : function(count){
            this.fileNameArr = [];
            this.count = count || 5;
            this.index = 0;
            this.create();
        },
        create : function (){
            $("bxAtt2").innerHTML = "<input type='file' name='file1' size='1'  hidefocus  style='cursor:hand'/>"
            $$('#bxAtt2 input')[0].onchange = this.file_change.bind(this,$$('#bxAtt2 input')[0]);   
        },
        file_change : function(f){
            var _name = f.value.replace(/\\/g,"/").replace(/(.*\/)(.*)/,"$2");
            if(this.fileNameArr.indexOf(_name)!=-1){
                alert('file existed');
                return;
            }
            this.fileNameArr.push(_name);
            var _n = document.createElement("nobr");
            _n.style.cssText = "float:left;margin-right:6;padding-top:3;color:darkgreen;font-size:12px";
            _n.appendChild(document.createTextNode(_name));
            var _font = document.createElement("font");
            _font.style.cssText = "color:red;font-weight:bold;cursor:hand;width:40px;";
            _font.appendChild(document.createTextNode(unescape("%d7")));
             _font.onclick = this.remove_file.bind(this,_n,_name);
            _n.appendChild(_font);
           
            f.style.display = 'none';
            _n.appendChild(f);
            $("bxAttList").insertBefore(_n,$("bxAtt"));
            new Effect.BlindDown(_n,{
                    scaleX: true,
                    scaleY : false,
                    afterSetup: function(effect) {
                        effect.element.makeClipping().setStyle({width: '0px'}).show(); 
                    }
            });
            if(this.count<=++this.index)
                Event.observe($('bxAtt1'),'click',function(){alert('you can upload '+this.count+' attachments maxiumn only.')}.bind(this));    
            else
                this.create();
        },
        remove_file : function(obj,_name){
            this.index--;
            this.fileNameArr.pop();
            $('bxAtt1').onclick = null;
            this.create();
           new Effect.BlindUp(obj,{
                scaleX: true,
                scaleY : false,
                afterFinishInternal: function(effect) {
                    $('bxAttList').removeChild(effect.element);
                } 
           });
        }
    })
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics