利用其它控件觸發file的click事件來選擇文件后,使用jquery.form.js中的submit方法提交時IE報錯:form.submit SCRIPT5: 拒絕訪問,其它瀏覽器正常,
<script> function fileclick(){ $("#file1").click(); } $(function(){ $("#btnSumbit").click(function(){ $("#form1").ajaxSubmit(); }); }) </script>
出問題的代碼如下:
<form id="form1" method="post" enctype="multipart/form-data"> <input type="file" id="file1" name="file1" style="display:none"/> <a herf="javascript:void(0)" onclick="fileclick()">上傳附件</a>
<input type="button" id="btnSubmit" value="提交"/> </form>
解決辦法:label的for屬性指向file
<form id="form1" method="post" enctype="multipart/form-data"> <input type="file" id="file1" name="file1" style="display:none"/> <label for="file1" style="cursor:pointer;">上傳附件</label>
<input type="button" id="btnSubmit" value="提交"/> </form>