看板 Ajax 關於我們 聯絡資訊
我打算用 iframe作檔案上傳的功能 可是現再發現一個問題, 如果我再HTML中直接加入 <iframe name="UpladFileProcess" id="UpladFileProcess" style="display:none"> </iframe> 就可以work..但是我現在想把 iframe藏起來 也就是用 Javascript....document.createElement("iframe") 可是我發現..可以work..但是..都是會另開新視窗..而不是在我 create的視窗當中出現.. 以下附上片斷程式碼.. 上傳的Sorce網頁 <form enctype="multipart/form-data" id="UploadFrom" method="post" name='UploadFrom'> <table id='UploadFile' > <tr> <td colspan="4"> <div id="Upload_1"> <input type="hidden" name='Key' value="<?=$Key ?>" /> <input type="text" name="FileName" size="30" value="請輸入檔案名稱" onclick="javascript:this.value=''"/>&nbsp; <input type="file" name='File' /> <input type="button" onClick="FileSubmit()"/></td> </div> <div id="Upload_2" style="display:none">Uploading...............Please Wait</div> </tr> </table> </form> JS code function FileSubmit(){ if(document.getElementById("UpladFileProcess")==null){ bodys=document.getElementsByTagName("body")[0]; iframe=document.createElement("iframe"); iframe.setAttribute('name','UpladFileProcess'); iframe.setAttribute('id','UpladFileProcess'); iframe.name="UpladFileProcess"; iframe.style.display='block'; document.body.appendChild(iframe); } FileForm=document.getElementById("UploadFrom"); FileForm.action="UploadFile.php"; FileForm.target=iframe.name;//這邊我有試過直接給名子..但是不行 //document.getElementById("Upload_1").style.display="none"; //document.getElementById("Upload_2").style.display="block"; document.UploadFrom.submit(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.70.73.186 ※ 編輯: expect7 來自: 61.70.73.186 (06/22 16:11)
ephesians:你的網頁有<body>標籤嗎? 06/22 16:34
expect7:有..iframe有成功新增 ... 06/22 16:40
ephesians:FileForm.target=iframe.name,之前iframe是區域變數 06/22 17:02
expect7:這行我有試過..直接打UpladFileProcess 06/22 17:36
expect7:結果一樣 06/22 17:37
expect7:FileForm.target="UpladFileProcess"..試過了.. 06/22 17:46