分享一个js实现的弹出层上传文件的窗口:

 
  
  1. function uploadWindow(attrId,productId,index){ 
  2.          
  3.             var html = "<div class='fitem'><form id='upload' method='post' enctype='multipart/form-data'>" 
  4.                 html += "<input type='hidden' value='"+attrId+"' name='productAttrId'>"; 
  5.                 html += "<input type='hidden' value='"+productId+"' name='productId'>"; 
  6.                 html += "选择图片:<input type='file' id='file' name='productPic'>"; 
  7.                 html += "<a class='easyui-linkbutton l-btn l-btn-plain'   iconcls='icon-ok' href='#'>"; 
  8.                 html += "<span>"; 
  9.                 html += "<span class='l-btn-text icon-ok' onclick='upload("+index+")' style='padding-left: 20px;'>保存</span></span></a>"; 
  10.                 html += "</form></div>"; 
  11.             var msgw,msgh,bordercolor;   
  12.             msgw=400;//提示窗口的宽度  
  13.             msgh=400;//提示窗口的高度  
  14.             titleheight=1 //提示窗口标题高度  
  15.             bordercolor="#99BBE8";//提示窗口的边框颜色  
  16.             titlecolor="#c51100";//提示窗口的标题颜色  
  17.               
  18.             var sWidth,sHeight;   
  19.             sWidth=screen.width;   
  20.             sHeight=screen.height;   
  21.             var bgObj=document.createElement("div");   
  22.             bgObj.setAttribute('id','bgDiv');   
  23.             bgObj.style.position="absolute";   
  24.             bgObj.style.top="0";   
  25.             bgObj.style.left="0";   
  26.             bgObj.style.width=sWidth + "px";   
  27.             bgObj.style.height=sHeight + "px";   
  28.             bgObj.style.zIndex = "10000";   
  29.             document.body.appendChild(bgObj);   
  30.               
  31.             var msgObj=document.createElement("div")   
  32.             msgObj.setAttribute("id","msgDiv");   
  33.             msgObj.setAttribute("align","center");   
  34.             msgObj.style.background="white";   
  35.             msgObj.style.border="1px solid " + bordercolor;   
  36.             msgObj.style.position = "absolute";   
  37.             msgObj.style.left = "50%";   
  38.             msgObj.style.top = "30%";   
  39.             msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";   
  40.             msgObj.style.marginLeft = "-225px" ;   
  41.             msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";   
  42.             msgObj.style.width = msgw + "px";   
  43.             msgObj.style.height =msgh + "px";   
  44.             msgObj.style.textAlign = "center";   
  45.             msgObj.style.lineHeight ="25px";   
  46.             msgObj.style.zIndex = "10001";   
  47.               
  48.             var title=document.createElement("h4");   
  49.             title.setAttribute("id","msgTitle");   
  50.             title.setAttribute("align","right");   
  51.             title.style.margin="0";   
  52.             title.style.padding="3px";   
  53.             title.style.background=bordercolor;   
  54.             title.style.border="1px solid " + bordercolor;   
  55.             title.style.height="18px";   
  56.             title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";   
  57.             title.style.color="white";   
  58.             title.style.cursor="pointer";   
  59.             title.innerHTML="关闭";   
  60.             title.onclick=function(){   
  61.             document.body.removeChild(bgObj);   
  62.             document.getElementById("msgDiv").removeChild(title);   
  63.             document.body.removeChild(msgObj);   
  64.             }   
  65.             document.body.appendChild(msgObj);   
  66.             document.getElementById("msgDiv").appendChild(title);   
  67.             var txt=document.createElement("p");   
  68.             txt.style.margin="1em 0" 
  69.             txt.setAttribute("id","msgTxt");   
  70.             txt.innerHTML=html;   
  71.             document.getElementById("msgDiv").appendChild(txt);   
  72.                  
  73.         } 
  74. attrId,productId,index是我自己用到的参数。