2015-08-28 63 views
2

enter image description here下面是我試圖本地存儲的代碼,我已經選擇的文件狀態,但刷新後它不存在。如何使用本地存儲?即使在頁面刷新後,如何使用本地存儲器在本地存儲輸入文件狀態?

<html> 
    <head> 
    <script> 
     function savedata(){ 
     localStorage.SetItem("file",getElementById("store").value); 
     } 
     window.onload = function(){ 
     document.getElementById("store").value = localStorage.getItem("file"); 
     } 
    </script> 
    </head> 
    <body> 
    <form> 
     <input type ="file" id = "store" onchange="savedata();"/> 
    </form> 
    </body> 
</html> 

當我上傳它顯示爲somefilename.png/jpg.But我刷新頁面後,未顯示任何文件choosen.I想我甚至刷新後,選擇了最後選定的文件名的文件。

即使我刷新頁面後,它應該顯示以前的文件名,而不是沒有文件選擇如何做到這一點?

後,我已經刷新文件時,它沒有表現出choosen enter image description here

+0

@Arun P Johny這些答案沒有給我任何明確的,這就是爲什麼我問 – CSiva

+0

https://developer.mozilla.org/en/docs/Web/HTML/Element/Input#File_inputs –

回答

0

input永遠騙你它的真正價值是什麼文件,所以你不能從客戶端的計算機敏感的路徑信息。唯一可以發現的是文件名,並且通過使用文件名,不可能將其設置爲之前的

+0

JavaScript中的local storage會工作嗎輸入類型=「文件」? – CSiva

相關問題