close

 

假設我們有一個 form Tag 需要動態調整 enctype 屬性來達到上傳檔案的需求,如下所示:

<form method="post" id="form1">
    <input type="file" name="file1" id="file1">
<form>

此時,我們原本只要取得 form 物件後去設定其 enctype 屬性即可,如下所示:
    document.getElementById("form1").enctype = "multipart/form-data";

這種寫法在 Firefox 是沒問題的,但是在 IE 中,如果僅如此設定,form 並不會造預想的那樣
變成 multipart/form-data 的編碼方式傳送,而是仍用預設的 application/x-www-form-urlencoded 編碼傳送資料,因此,要多加以下的寫法才能在 IE 上運作正常
    document.getElementById("form1").encoding = "multipart/form-data";

arrow
arrow
    全站熱搜

    大笨鳥 發表在 痞客邦 留言(0) 人氣()