现在的位置: 首页 > 综合 > 正文

php 进度条

2017年09月13日 ⁄ 综合 ⁄ 共 1075字 ⁄ 字号 评论关闭
$progList=array(1,2,3,4,5,6,7,8,9,0,12,45,36,48,51,5,4,55,4);
Delete($progList);
function Delete($progList)
{
   set_time_limit(0);
   $step = 0;
   $count=count($progList);
   print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><div id="waikuo" style="float:left;background-color:#FFFFFF;width:200px;height:8px;padding:1px;border:#CCCCCC 1px solid;overflow:hidden;"><div id="jindu" style="float:left;width:0;height:8px;background-color:#669966;overflow:hidden;"> </div></div></body></html> ';
   
   foreach ($progList as $prog)
   {
      usleep(50000); //设置循环一次的时间
      $step+=200*(1/$count); //计算得到,一次所要走的步长
      echo '<script> document.getElementById("jindu").style.width = "'.$step.'px"; </script>'; 
      ob_flush(); 
      flush();
   }   
   echo '<script> document.getElementById("jindu").style.display="none"; </script>';
   echo '<script> document.getElementById("waikuo").style.display="none"; </script>';
}

foreach循环里可以进行其他操作,比如数据库数据的读取或插入。

这样就实现了,根据操作的进度来走进度条。

抱歉!评论已关闭.