惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 雪域月光

windows如何查看cpu是否支持aux2指令集 git commit错误 error: bad signature 0x00000000 fatal: index file corrupt git pull时遇到error: cannot lock ref 'xxx': ref xxx is at (一个commitID) but expected的解决办法 git tortoise commit时出错 fatal : unable to read f77cxxxxxxxxxxx git unable to resolve reference 'refs/remotes/gitee/20210825-add-Projet-coreScene': reference broken git如何获取远端仓库新分支 git 清除本地修改 项目添加git忽略文件无效的处理 git tortoise commit 出现 fatal bad revidion head freeswitch 使用info显示的通道变量 freeswitch dialplan 基础 字符编码:Unicode和UTF-8之间的关系 NET(C#):关于正确读取中文编码文件 UTF-8和GBK有什么区别 gb2312,gbk,utf8的区别 PHP的ob_flush()与flush()区别 微信小程序如何实现和微信客服通话? 微信小程序如何接入? 微信小程序和微信公众号的id是一个吗
php+javascript实现的动态显示服务器运行程序进度条功能示例
雪域月光 · 2018-04-24 · via 博客园 - 雪域月光

本文实例讲述了php+javascript实现的动态显示服务器运行程序进度条功能。分享给大家供大家参考,具体如下:

经常有这样的业务要处理,服务器上有较多的业务需要处理,需要分批操作,于是就需要一个提示客户现在完成进度的进度条。

这个是php+javascript的进度条。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

<?php

for ($i = 0; $i < 500; $i++) {

  $users[] = 'Tom_' . $i;

$width = 500;           

$total = count($users);      

$pix = $width / $total;      

$progress = 0;          

?>

<html>

<head>

  <title>动态显示服务器运行程序的进度条</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <style>

  body, div input { font-family: Tahoma; font-size: 9pt }

  </style>

  <script language="JavaScript">

  <!--

  function updateProgress(sMsg, iWidth)

  {

    document.getElementById("status").innerHTML = sMsg;

    document.getElementById("progress").style.width = iWidth + "px";

    document.getElementById("percent").innerHTML = parseInt(iWidth / <?php echo $width; ?> * 100) + "%";

   }

  </script>

</head>

<body>

<div style="margin: 4px; padding: 8px; border: 1px solid gray; background: #EAEAEA; width: <?php echo $width+8; ?>px">

  <div><font color="gray">如下进度条的动态效果由服务器端 PHP 程序结合客户端 JavaScript 程序生成。</font></div>

  <div style="padding: 0; border: 1px solid navy; width: <?php echo $width; ?>px">

  <div id="progress" style="padding: 0; border: 0; width: 0px; text-align: center;  height: 16px"></div>

  </div>

  <div id="status"> </div>

  <div id="percent" style="position: relative; top: -30px; text-align: center; font-weight: bold; font-size: 8pt">0%</div>

</div>

<?php

flush(); 

foreach ($users as $user) {

  for ($i = 0; $i < 1000000; $i++) {

    ;;

   }

?>

<script language="JavaScript">

  updateProgress("正在操作用户“<?php echo $user; ?>” ....", <?php echo min($width, intval($progress)); ?>);

</script>

<?php

  flush(); 

  $progress += $pix;

?>

<script language="JavaScript">

  updateProgress("操作完成!", <?php echo $width; ?>);

</script>

<?php

flush();

?>

</body>

</html>

运行效果如下: