2012-10-26 34 views
0

我有一些jQuery的,它的工作原理我Chrome中的問題和Firefox,但不是在IEjQuery的提交無法在IE

代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<meta content="IE=edge" http-equiv="X-UA-Compatible"/> 

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> 
</script> 
</head> 

<body> 

<form method='post' name='aform' action='test2.html'> 
<input type='file' value='Upload Billede' name='image[fileupload]' /><input type='button' class='upload image[fileupload]' value='Upload Billede' /> 
</form> 
<script type="text/javascript"> 
$(document).ready(function(){ 

bind_file_upload();  
}); 
function bind_file_upload() 
{ 
    var target_id; 
    $("[name='image[fileupload]']").change(function(event){ 
     $("[name='aform']").submit(); 
    }); 
    $(".upload").click(function(){ 
     $("[name='image[fileupload]']").click(); 
    }); 
} 

</script> 

</body> 
</html> 

的問題是,當我直接使用文件控制通過瀏覽按鈕頁面提交,但是當我使用我自己的上傳按鈕它會觸發filedialog,但是當我選擇一個文件,然後按打開jQuery失敗,權限被拒絕。

我做錯了什麼。

在此先感謝

回答

4

你的問題是,當你在模擬文件輸入點擊,IE標誌形式的安全威脅,並不會發送。 對於IE,你必須讓用戶自己點擊文件輸入。

編輯

如果你真的想自定義文件輸入,你可以考慮一下:http://www.quirksmode.org/dom/inputfile.html

或者你可以使用閃光燈/的Silverlight插件,只要你想,你可以自定義,或用於Internet Explorer的ActiveX控件。

+0

終於IE得到了正確的東西。 –

+0

感謝您的回答 –

0

正如Gregoire D.所說,IE會阻止您的表單提交,因爲用戶不直接點擊文件輸入。因此,對於IE瀏覽器我用下一個解決方案

http://www.quirksmode.org/dom/inputfile.html

有提供有兩種可能的解決方案。我更喜歡第一個(基於CSS)解決方案。