日期:2014-05-16  浏览次数:20344 次

js 动态追加file元素
function createInput(filedata){   
            var div1  =  document.getElementById("div_Pic")
            var filename = document.getElementsByName("filename")
            var pathbool = true;
            var a = 1;
            if(filename.length>0){
            for(var i = 0;i<filename.length;i++){
          //判断是否存在没有浏览项
            if(filename[i].value == "" ||filename[i].value==null||filename[i].value==undefined){
            pathbool = false;
            }
            //判断是否存在相同的文件路径
            if(filedata.value == filename[i].value){
            a = a+1;
            }
            }
            }
            if(pathbool&&a<=2) {
            var f   =   document.createElement("<input type='file' name='filename' onchange='javascript:createInput(this)'/>");
        div1.appendChild(f);
        //div1.appendChild(d)
            }
            if(a>2){
            b
            div1.removeChild(filedata);
            if(pathbool){
            var f   =   document.createElement("<input type='file' name='filename' onchange='javascript:createInput(this)'/>");
        div1.appendChild(f);
            }
            }
           

</script>