本文介绍了IE8只提交与按钮,没有提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,这是奇怪的,并且它大约一个月前就为我工作,之前我做了一堆code更新。反正这个问题不过是现场提交处理程序甚至不会在IE8上运行,如果我在一个按钮,点击运行它,它的工作原理。请看下图:
HTML
<标签>添加附件< /标签>
<窗体类=file_upload方法=邮报是enctype =的multipart / form-data的目标=upload_target行动=>
<输入名称=二进制ID =文件大小=27类型=文件/>< BR />
< BR><输入类型=提交名称=行动值=上传/>< BR />
<输入类型=按钮级=测试值=测试>
< IFRAME类=upload_targetNAME =upload_targetSRC =的风格=>< / IFRAME>
< /形式GT;
<标签>附件< /标签>
< UL类=upload_output>
<李类=NOFILES>(无文件进行添加,但)LT; /李>
< / UL>
JavaScript的:
函数file_upload($ theform,ITEM_ID){
$ theform.attr('行动','io.cfm行动= updateitemfile和放大器; ITEM_ID ='+ ITEM_ID);
如果($ theform.find('[type = file]')VAL()长度GT; 0){
$(IFRAME)。一('LOAD',函数(){
$实况preview.agenda({
动作:'得到',
ID:ITEM_ID,
类型:'项',
回调:函数(JSON){
。$ theform.siblings('。upload_output)追加('&LT;李风格=显示:无级=文件上传&GT;&LT;目标=空白 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> &LT;风格=颜色:红色称号=删除文件? href="#deletefile-'+json[0].files.slice(-1)[0].item_file_id+'">[X]</a></li>').children('li').fadeIn();
$ theform.siblings('。upload_output)找到删除()。(NOFILES。')。
}
});
//重新设置文件的输入。只有这样,才能得到它跨浏览器兼容,因为重置VAL不了了之
//不IE8中工作。它忽略VAL('')将其复位。
$ theform.append('&LT;输入类型=重置的风格=显示:无&GT;')。子女([类型=重置]')点击()删除()。
});
}
其他{
$ .alert('无文件选择');
返回false;
}
}
/ *文件上传活动* /
//在模态当他们选择上传
$('。file_upload)。住('提交',函数(事件){
警报(世界你好);
file_upload($()$('议程模态。')ATTR(数据defaultitemid')'议程模态.file_upload。');
});
/ *这是code,使得它的工作......,但我不希望它!应该提醒的Hello World提交按钮! * /
$('测试')生活('点击',函数(事件){
$('。file_upload)提交()。
});
解决方案
这是由设计,而不是在所有隔离到IE 8一直以来,这样,在所有浏览器。
在提交
如果调用提交
法的事件不会发生,只有当你提交表单使用提交按钮。
So, this is strange, and it was working for me about a month ago, before I made a bunch of code updates. Anyways the issue is the live submit handler wont even run in IE8, however, if i run it on a button click, it works. See below:
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();
});
解决方案
That is by design, and not at all isolated to IE 8. It has always been that way, in all browsers.
The submit
event doesn't happen if you call the submit
method, only when you submit the form using the submit button.
这篇关于IE8只提交与按钮,没有提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!