ajaxupload 使用例子

ajaxuplaod下载地址:

http://pan.baidu.com/share/link?shareid=297437689&uk=739224795

文章例子压缩包:

http://pan.baidu.com/share/link?shareid=299848842&uk=739224795


示例代码:

<html>
	<head>
		<title>ajaxupload上传</title>
		<meta charset="utf-8"/>
		<style type="text/css">
			.divMain{
				position:absolute;
				width:140px;
				height:100px;
				padding-left:60px;
				padding-top:40px;
			}
			#upload{
				width:150px;
				height:30px;
			}
			.content{
				width:300px;
				height:200px;
			}
		</style>
		<script type="text/javascript" src="./jquery.1.8.js"></script>
		<script type="text/javascript" src="./ajaxupload.js"></script>
	</head>
	<body>
		<div class="divMain">
			<button id="upload">文件上传</button>
			<div class="content"></div>
		</div>
	</body>
	<script type="text/javascript">
		/*
				ajaxupload上传
			*/
		   $(document).ready(function(){
			    var button = $('#upload'), interval;
			    var fileType = "all",fileNum = "one"; 
			    new AjaxUpload(button,{
			        action: './upload.php',
			        name: 'userfile',
			        onSubmit : function(file, ext){
			            if(fileType == "pic")
			            {
			                if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)){
			                    this.setData({
			                        'info': '文件类型为图片'
			                    });
			                } else {
			                    $('<li></li>').appendTo('.files').text('非图片类型文件,请重传');
			                    return false;               
			                }
			            }
			            button.text('文件上传中');
			            if(fileNum == 'one')
			                this.disable();
			            interval = window.setInterval(function(){
			                var text = button.text();
			                if (text.length < 14){
			                    button.text(text + '.');                    
			                } else {
			                    button.text('文件上传中');             
			                }
			            }, 200);
			        },
			        onComplete: function(file, response){//上传成功的函数;response代表服务器返回的数据
							//清楚按钮的状态
							button.text('文件上传');
				            window.clearInterval(interval);
				            this.enable();
							//修改下方div的显示文字
						if('success'==response){
							$(".content").text("上传成功");
						}else{
							$(".content").text("上传失败");
						}
			        }
					});
			});
	</script>
</html>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值