[英]IE8 only submits with button, not submit?
因此,這很奇怪,大約一個月前,在我進行了大量代碼更新之前,它已經為我工作了。 無論如何,問題是實時提交處理程序甚至不會在IE8中運行,但是,如果我在單擊按鈕時運行它,則它會起作用。 見下文:
的HTML
<label>Add Attachment</label>
<form class="file_upload" method="post" enctype="multipart/form-data" target="upload_target" action="">
<input name="binary" id="file" size="27" type="file" /><br />
<br><input type="submit" name="action" value="Upload" /><br />
<input type="button" class="test" value="test">
<iframe class="upload_target" name="upload_target" src="" style=""></iframe>
</form>
<label>Attachments</label>
<ul class="upload_output">
<li class="nofiles">(No Files Added, Yet)</li>
</ul>
JavaScript:
function file_upload($theform,item_id){
$theform.attr('ACTION','io.cfm?action=updateitemfile&item_id='+item_id);
if($theform.find('[type=file]').val().length > 0){
$('iframe').one('load',function(){
$livepreview.agenda({
action:'get',
id:item_id,
type:'item',
callback:function(json){
$theform.siblings('.upload_output').append('<li style="display:none" class="file-upload"><a target="blank" href="io.cfm?action=getitemfile&item_file_id='+json[0].files.slice(-1)[0].item_file_id+'">'+json[0].files.slice(-1)[0].file_name+'</a> <a style="color:red" title="Delete file?" href="#deletefile-'+json[0].files.slice(-1)[0].item_file_id+'">[X]</a></li>').children('li').fadeIn();
$theform.siblings('.upload_output').find('.nofiles').remove();
}
});
//Resets the file input. The only way to get it cross browser compatible as resetting the val to nothing
//Doesn't work in IE8. It ignores val('') to reset it.
$theform.append('<input type="reset" style="display:none">').children('[type=reset]').click().remove();
});
}
else{
$.alert('No file selected');
return false;
}
}
/* FILE UPLOAD EVENTS */
//When they select "upload" in the modal
$('.file_upload').live('submit',function(event){
alert('hello world');
file_upload($('.agenda-modal .file_upload'),$('.agenda-modal').attr('data-defaultitemid'));
});
/* This is the code that makes it work..., but i dont want it! it should alert hello world on the submit button! */
$('.test').live('click',function(event){
$('.file_upload').submit();
});
這是設計使然,絕不與IE 8隔離。在所有瀏覽器中,一直都是這樣。
如果您調用submit
方法,則僅在使用“提交”按鈕提交表單時,才會發生submit
事件。
而不是創建重置按鈕,而是模擬點擊事件並銷毀它-為什么不只是
$('.file_upload').reset();
您真的需要現場提交表格嗎? 如果按鈕一直都停留在DOM中,請使用常規的click事件,例如
$('.test').click(function(){ $('.file_upload').submit(); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.