欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一个简单的异步上传方法

程序员文章站 2022-04-08 09:37:15
...
<! DOCTYPE html>

< html>

< head>

< meta charset ="GB2312" >

< title> Insert title here </title >

< script type ="text/javascript" src= "jquery.js"></ script >

< script type ="text/javascript" >

$(document).ready( function (){

      $( "#i_1" ).load( function(){

             var url = $("#i_1" ).contents().find( "#pic").html();

             if (url != null){

                  $( "#tag_img" ).attr("src" ,url);

            }

      });

});

</ script>

</ head>

< body>

< img id= "tag_img" src = "" />

< form enctype ="multipart/form-data" action= "upload_pic.php" method ="post" target= "upload_target">

     <input type= "file" name ="img" class= "file" value ="" />

     <input type= "submit" name ="uploadimg" value= "上传" />

</ form>

< iframe id= "i_1" name = "upload_target"></ iframe >

</ body>

</ html>

重点:

1.form中的axtion="处理图片的有效页面"

2.form中的target="iframe的name属性值"

3.JS中必须要有可以等待iframe加载完后处理iframe返回过来的图片地址。