MozTW 討論區
https://forum.moztw.org/

一個HTML DOM FileUpload Object的問題
https://forum.moztw.org/viewtopic.php?f=13&t=3580
1 頁 (共 1 頁)

發表人:  Kej [ 2004-10-18, 23:27 ]
文章主題 :  一個HTML DOM FileUpload Object的問題

先附上程式碼,如下:
代碼:
<html>
<head>
<title>xyz</title>
<head>

<script Language="JavaScript">
function openfile(){
   document.getElementById("ifile").click();
}
</script>

<style type="text/css">
.class11{color:#0000FF;cursor:pointer;}
</style>

<body>
<form name="frm1" action="nexturl.php" method="post">
<input type="file" id="ifile" style="display:none">
<u class="class11" onclick="openfile();">click here to select a file</u>
<input type="submit" value="submit">
</form>
</body>
</html>


我想要用一串文字(或用圖片)來作出實際點擊FileUpload Tag的效果
上面那串code在IE下運作正常,但是在FireFox卻毫無反應
請問一下究竟是程式碼有問題呢?還是FireFox根本不支援FileUpload.click()?

先謝謝各位前輩...

發表人:  member [ 2004-10-19, 01:25 ]
文章主題 : 

你的 form 標籤應該宣告為 enctype="multipart/form-data"
另外, 你可使用 document.fm1.submit();

發表人:  Kej [ 2004-10-20, 20:12 ]
文章主題 : 

member 寫:
你的 form 標籤應該宣告為 enctype="multipart/form-data"
另外, 你可使用 document.fm1.submit();

謝謝你的回答
post時不知道在想什麼,忘了加上enctype宣告 :oops:
不過重點是下面這行script無法執行
代碼:
document.getElementById("ifile").click();

不知道這是不是只有IE才能執行?

發表人:  訪客 [ 2006-03-29, 14:51 ]
文章主題 : 

是的,mozilla和Opera均不支持click()方法

The click() method allows you to simulate a click on a form field. Checkboxes get toggled, radios selected, and so on. Unfortunately Mozilla and Opera haven't added this method to file upload fields. I wonder why, adding it is not really a security risk since the worst that can happen is that the file selection window pops up.

So unfortunately we cannot use this simple solution

發表人:  kourge [ 2006-03-30, 22:13 ]
文章主題 : 

這就是為什麼在 Gmail 中,按 Add attachment,IE 會跳出瀏覽檔案的對話方塊,在 Firefox 中就得自己按[瀏覽]

1 頁 (共 1 頁) 所有顯示的時間為 UTC + 8 小時
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/