0

我有一个基于 IFRAME 的上传文件。它适用于 Firefox 和 Google Chrome,但适用于 Internet Explorer 8,当您发送文件时,整个页面都会刷新。按照我的代码:

JS:

  function test(){
     iframe = document.createElement("IFRAME");  
     iframe.name = "iframe_upload";
     iframe.id = "iframe_upload"; //some browsers target by id not name
     document.body.appendChild(iframe);
     document.getElementById("test").target = "iframe_upload";
  }

HTML:

<form id="test" method="post" target="iframe_upload" enctype="multipart/form-data" onsubmit="javascript:test()" action="test.php">
  <input name="image" type="file" /> 
  <input type="submit" value="Submit" />
</form>
4

1 回答 1

1

行动回报onsubmit

onsubmit="return test();"

false从函数返回:

function test(){
   iframe = document.createElement("IFRAME");  
   iframe.name = "iframe_upload";
   iframe.id = "iframe_upload"; //some browsers target by id not name
   document.body.appendChild(iframe);
   document.getElementById("test").target = "iframe_upload";
   return false;
}
于 2013-11-08T13:52:33.467 回答