2013-04-12 39 views
0

我的問題是var myFileList = document.getElementById('upload_file').files;沒有獲取文件,也沒有在代碼中進行任何進一步操作,當我嘗試獲取我已「動態創建」的信息時我的PHP文件。但是,如果我在HTML頁面中創建相同的表格並將表格附加到表格中,則代碼完美地工作。通過javascript/ajax在動態創建的表內創建表單時出錯php

總結:因爲表格來自PHP,表格不起作用。

我在PHP山坳其形式將appendChild到像這樣做:

$display_String .= '<td><div id = "image'.$f1.'"></div></td>'; 

而且使得形式的JavaScript是:

var f = document.createElement("form"); 
f.setAttribute('enctype',"multipart/form-data"); 
f.setAttribute('method',"post"); 
f.setAttribute('action',"uploadImage.php"); 


var i = document.createElement("input"); //input element, text 
i.setAttribute('type',"file"); 
i.setAttribute('name',"upload_file"); 
i.setAttribute('id',"upload_file"); 
i.setAttribute('size',4); 

f.appendChild(i); 
document.getElementById("image1").appendChild(f); 

「圖像1」這個名字在PHP表中的div, 正如我所說,如果我在這樣的html文件中靜態創建表,它可以正常工作

<table> 
    <tr> 
     <td>test </td> 
     <td> bah </td> 
    </tr> 
    <tr> 
     <td> <div id ="image1"> </div> </td> 
     <td> col2</td> 
    </tr> 
    <tr> 
     <td></td> 
     <td> col2 </td> 
    </tr> 
    </table> 

我知道這將是非常簡單的事情, 也抱歉,我無法使用JQuery。

回答

0

嘗試將其放入文檔加載時執行的函數中。

document.onload = doYourThing(); 

function doYourThing() { 
    //Your code here 
} 
+0

它已經是,文檔加載然後用戶搜索表來自的東西。然後用戶點擊編輯,表單出現。對不起,應該已經明確了 –

+0

其他人有什麼想法? –