模仿jquery的fileupload插件
仅需要new一个对象,将上传后台的url和点击触发上传的元素id传给对象,就可以自从实现上传
暂不支持IE
<html>
<body>
<a href="#" id="a_upload">上传</a>
</body>
</html>
<script src="lib_shb_fileupload.js"></script>
<script type="text/javascript">
var fu = new SHBFileUpload("doUpload.jsp",'a_upload');
fu.callback = function(){
console.log(fu.status) ;
console.log(fu.responseText) ;
}
</script>
js源码如下:
/**
*简单的文件上传
*@author:索洪波
*@qq:609690891
*@version:1.0
*/
/**
*@SHBFileUpload
*@param:url上传url
*@param:id 出发上传操作的元素id
*/ function SHBFileUpload(url,id){
this.url = url ;
this.id = id ;
this.iframe = null ;
this.form = null ;
this.input = null ;
this.status = 'init' ;
this.responseText = '' ;
this.timeout = 100 ; this.init();
}
SHBFileUpload.prototype.createIframe = function(){
var iframe = document.createElement('iframe') ;
iframe.id = 'SHB_FU_Frame' ;
iframe.name = 'SHB_FU_Frame' ;
iframe.style.display = 'none' ;
document.body.appendChild(iframe);
this.iframe = iframe ;
}
SHBFileUpload.prototype.createForm = function(){
var form = document.createElement('form') ;
form.action = this.url ;
form.id = 'SHB_FU_Form' ;
form.name = 'SHB_FU_Form' ;
form.method = 'post' ;
form.encoding = 'multipart/form-data' ;
form.target = 'SHB_FU_Frame' ;
form.style.display = 'none' ;
this.form = form ; var input = document.createElement('input') ;
input.type = 'file' ;
input.id = 'SHB_FU_Input' ;
input.name = 'SHB_FU_Input' ;
input.style.display = 'none' ;
var self = this ;
input.onchange = function(){self.doUpload()} ;
this.input = input ; form.appendChild(input) ;
document.body.appendChild(form) ;
}
SHBFileUpload.prototype.doUpload = function(){
this.status = 'sending' ;
var self = this ;
this.iframe.onload = function(){self.hasLoad()} ;
this.form.submit();
}
SHBFileUpload.prototype.init = function(){
this.createIframe() ;
this.createForm() ;
var self = this ;
document.getElementById(this.id).onclick = function(){self.input.click()} ;
}
SHBFileUpload.prototype.hasLoad = function(){
var iframe = this.iframe ;
this.status = 'success' ;
if(iframe.contentWindow){
this.responseText = iframe.contentWindow.document.body?iframe.contentWindow.document.body.innerHTML:"";
}else if(iframe.contentDocument){
this.responseText = iframe.contentDocument.document.body?iframe.contentDocument.document.body.innerHTML:"";
}
this.callback() ;
}
SHBFileUpload.prototype.callback = function(){}
模仿jquery的fileupload插件的更多相关文章
- jQuery模仿人类打字效果插件typetype
typetype是一款模仿人类打字效果的jQuery插件,typetype非常轻巧,文件不到2K,gzipped压缩后只有578字节,但模仿的效果非常逼真,一字一字的顿出和回删效果,让人惊叹不止,喜欢 ...
- jquery.fileupload插件的简易使用日志
来源:http://yixiandave.iteye.com/blog/1897330 本文内容主要包含fileupload插件传递参数和取回服务器返回数据的方法 jquery.fileupload官 ...
- 使用jQuery.FileUpload插件和Backload组件裁剪上传图片
□ 思路 1.自定义控制器继承Backload的默认控制器BackloadController2.自定义一个jQuery File Upload初始化js文件,使用自定义控制器的方法3.在视图页面调用 ...
- 推荐几款jquery图片切换插件
一.前言 毕业季到了,大家都在匆匆忙忙的记录大学里最美好的时光,照片中各种花式.各种姿势都涌现出来了.这么多的照片怎么展示出来给自己的好友看呢?有人选择做成视频,有人选择ps之后做成图片集,而我选择利 ...
- 提升用户体验的最佳免费 jQuery 表单插件
网页表单是一个老生常谈的话题.出于这样或那样的目的,一些示例中都会包括用户注册,电子商务结算,用户设置甚至联系人表格.而输入栏是非常容易用现代的CSS3技术来应用样式.但是到底什么决定整体用户体验? ...
- jQuery为开发插件提拱了两个方法:jQuery.fn.extend(); jQuery.extend();
jQuery为开发插件提拱了两个方法,分别是: jQuery.fn.extend(); jQuery.extend(); jQuery.fn jQuery.fn = jQuery.prototype ...
- jQuery 人脸识别插件,支持图片和视频
jQuery Face Detection 是一款人脸检测插件,能够检测到图片,视频和画布中的人脸坐标.它跟踪人脸并输出人脸模型的坐标位置为一个数组.我们相信,面部识别技术能够给我们的 Web 应用带 ...
- myWaterfall - jQuery瀑布流布局插件
myWaterfall - jQuery瀑布流布局插件 Demo http://jsfiddle.net/q3011893/p5k2ogy8/embedded/result,html,css,js/ ...
- 推荐15款最佳的 jQuery 分步引导插件
当用户浏览到一个网站,它可能从不知道如何浏览,如何操作网站或 Web 应用程序的内容和流程.在这篇文章中,我们编制了一些最好的 jQuery 引导插件列表.你会发现这些插件对于提高你的网站的整体用户体 ...
随机推荐
- C socket post数据到url
#define HOST_SERVER_IP "192.168.1.15" #define HOST_PORT 80 int gsh_post_clients(const char ...
- N皇后问题——递归求解
比较简单,废话不说,上代码: public class NQueen { //比如:position[1]=3,表示第一行的第三列有一个皇后 private int [] position; //总的 ...
- LPC1788定时器使用
#ifndef __TIM_H_ #define __TIM_H_ #include "common.h" extern u8 tim1_mr0_flag; void tim0_c ...
- width这样读取出来是一个字符串,并且带有单位,但是offsetwidth返回的是一个数值。
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <title> ...
- C# GridView Edit & Delete, 点击Delete的时候弹出确认框
1. 使用GridView自带属性ShowEditButton和ShowDeleteButton,均设为True <Columns> ... <asp:CommandField S ...
- nodejs nodemailer中间件
var stransporter = nodemailer.createTransport({ host:smtp-163.com', //适合163 secureConnection: true, ...
- 【ural1297】 Palindrome
http://acm.timus.ru/problem.aspx?space=1&num=1297 (题目链接) 题意 求最长回文子串 Solution 后缀数组论文题 穷举每一位,然后计算以 ...
- Intent的概念及应用(二)
------siwuxie095 1.Intent过滤器 intent-filter 相关选项 如果多个Activity拥有同样的action,在启动时这个action时的情况: 首先在LearnIn ...
- Spring 之 示例(Java之负基础实战)
接 Spring 之 配置 里面的代码. 现在要进行Controller的开发. 1.引用类 import org.springframework.web.servlet.mvc.Controller ...
- 按ctrl + c 播放下一曲音乐
./a.out . #include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<dirent. ...