2010-09-02 158 views
0

所以,這很奇怪,大約一個月前它在爲我工作,在我做了一堆代碼更新之前。無論如何,問題是實時提交處理程序不會運行在IE8中,但是,如果我在按鈕上運行它,它就可以工作。請看下圖: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(); 
}); 
+0

只是一個快速的完整性檢查 - 所有的網址都由同一個域名服務? ie8引入了一些更好的XSS防禦措施,所以可以更嚴格地執行相同的原產地政策...... – Basic 2010-09-02 23:15:34

+0

是的:(它的全部相同的領域...而且就像我說的,它在按下按鈕時起作用,而不是提交... – 2010-09-02 23:20:59

回答

-1
  1. ,而不是建立復位按鈕,模擬點擊事件,並摧毀它 - 爲什麼不直接

    $('.file_upload').reset(); 
    
  2. 你是否eally需要提交表格?如果按鈕停留在DOM所有的時間,使其使用正常的單擊事件像

    $('.test').click(function(){ 
        $('.file_upload').submit(); 
    }); 
    
+0

重置在IE8中根本不起作用,只是保留在那裏相信我......我認爲它是一個醜陋的黑客,但是.reset()什麼都沒做。 表單不是靜態的。表單是通過DOM中的一種「模板」自動生成的,然後將其克隆和操作,然後放入模態框中。 – 2010-09-02 23:19:33

0

這是由設計,而不是在所有隔離到IE 8,它一直都是這樣,在所有瀏覽器中。

只有當您使用提交按鈕提交表單時,如果調用submit方法,submit事件纔會發生。

+0

所以...我該如何解決這個問題?它正在工作,好吧,現場提交工作之前我做了代碼更新,我可以隱藏提交按鈕並輸入type =「button」按鈕並擁有該點擊處理程序,它只是醜陋的... – 2010-09-02 23:21:45