2016-01-08 86 views
0

我有這個腳本,它通過iframe上傳文件很好...即時通訊使用它在一個循環,所以這許多形式像這樣..但document.getElementById(div_id).innerHTML = "Uploading..."; 只適用於第一個...任何線索如何解決這個問題?通過JavaScript在一個循環中上傳文件只顯示上傳一次

<script language="Javascript"> 
    function fileUpload(form, action_url, div_id) { 
     // Create the iframe... 
     var iframe = document.createElement("iframe"); 
     iframe.setAttribute("id", "upload_iframe"); 
     iframe.setAttribute("name", "upload_iframe"); 
     iframe.setAttribute("width", "0"); 
     iframe.setAttribute("height", "0"); 
     iframe.setAttribute("border", "0"); 
     iframe.setAttribute("style", "width: 0; height: 0; border: none;"); 

     // Add to document... 
     form.parentNode.appendChild(iframe); 
     window.frames['upload_iframe'].name = "upload_iframe"; 

     iframeId = document.getElementById("upload_iframe"); 

     // Add event... 
     var eventHandler = function() { 

       if (iframeId.detachEvent) iframeId.detachEvent("onload", eventHandler); 
       else iframeId.removeEventListener("load", eventHandler, false); 

       // Message from server... 
       if (iframeId.contentDocument) { 
        content = iframeId.contentDocument.body.innerHTML; 
       } else if (iframeId.contentWindow) { 
        content = iframeId.contentWindow.document.body.innerHTML; 
       } else if (iframeId.document) { 
        content = iframeId.document.body.innerHTML; 
       } 

       document.getElementById(div_id).innerHTML = content; 

       // Del the iframe... 
       setTimeout('iframeId.parentNode.removeChild(iframeId)', 250); 
      } 

     if (iframeId.addEventListener) iframeId.addEventListener("load", eventHandler, true); 
     if (iframeId.attachEvent) iframeId.attachEvent("onload", eventHandler); 

     // Set properties of form... 
     form.setAttribute("target", "upload_iframe"); 
     form.setAttribute("action", action_url); 
     form.setAttribute("method", "post"); 
     form.setAttribute("enctype", "multipart/form-data"); 
     form.setAttribute("encoding", "multipart/form-data"); 

     // Submit the form... 
     form.submit(); 

     document.getElementById(div_id).innerHTML = "Uploading..."; 
    } 
    </script> 

    <!-- index.php could be any script server-side for receive uploads. --> 
    <form> 
    <input type="file" name="myFile" /></br> 
     <input type="hidden" name="fid" readonly value="<?php echo $fid;?>"> 
     <input type="hidden" name="numerolinha" readonly value="<?php echo $loader;?>"> 
     <input type="hidden" name="contador" readonly value="<?php echo $id_postt1."linha_".$events[0]; ?>"> 
    <input type="button" value="upload" 
      onClick="fileUpload(this.form,'http://www.toppromomkt.com/wp-content/themes/toppromo/wallet_upload.php','upload'); return false;" > 
    <div id="upload"></div> 
    </form></div> 
+0

你如何設置div ID?你確定他們是獨一無二的嗎? – AlexBay

+0

我是一個改編的腳本....多數民衆贊成在一定的問題..但我無法改變該部分的腳本 –

+0

作爲一個側面說明,你不需要使用'語言'屬性'腳本'標籤;實際上它已經[已經過時了很長時間](https://www.youtube.com/watch?feature=player_detailpage&v=Y2Y0U-2qJMs#t=827)(它在過去一段時間已經被棄用了,該視頻來自2006年!)。一個簡單的無屬性''標籤將工作得很好。所有支持'script'標籤的瀏覽器都默認爲JavaScript。 –

回答

0

我修復它...我用$g++;,現在我的上傳作爲unik id。 tks to you all

<input type="button" value="upload" 
     onClick="fileUpload(this.form,'http://www.toppromomkt.com/wp-content/themes/toppromo/wallet_upload.php','upload<?php echo $g ?>'); return false;" > 
<div id="upload<?php echo $g ?>"></div> 
相關問題