日期:2014-05-16 浏览次数:20593 次
<html>
<title>PHP+Ajax带进度条文件上传</title>
<head>
<style type="text/css">
#progress{
border:2px red solid;
width:200px;
height:20px;
display:none;
}
#pecent{
background-color:green;
display:block;
width:0px;
height:20px;
color:yellow;
}
</style>
</head>
<body>
<iframe style="display:none" name="ifm"></iframe>
<form enctype="multipart/form-data" method="POST" action="upload2.php" target="ifm" name="myform">
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="remark" >
<input type="file" name="upfile"/>
<input type="submit" value="上传" name="sub"/>
</form>
<div id="progress" class="before"><span id="pecent"></span></div>
<script type="text/javascript">
(function(){
function addEvent( node, type, listener ) {
if (node.addEventListener) {
// W3C method
node.addEventListener( type, listener, false );
return true;
} else if(node.attachEvent) {
// MSIE method
node['e'+type+listener] = listener;
node[type+listener] = function(){node['e'+type+listener]( window.event );}
node.attachEvent( 'on'+type, node[type+listener] );
return true;
}
// Didn't have either so return false
return false;
};
var submit=document.forms["myform"];
addEvent(submit,'submit',startUpload);
var begin;
var request;
var rdm;
var pec=document.getElementById("pecent");
function startUpload()