Ajax+PHP实现的模拟进度条功能示例

yipeiwu_com6年前PHP代码库

本文实例讲述了Ajax+PHP实现的模拟进度条功能。分享给大家供大家参考,具体如下:

一 代码

fun.js:

function progress(){
  setInterval("beginProgress()", 200);
}
function beginProgress(){
  $.get("progress.php", null, function(data){
     $("#pg").css("width", data+"%");
     $("#pgtext").html("The progress is "+data+"%");
  });
}

index.php:

<!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=gb2312" />
<title>jQuery制作进度条</title>
</head>
<script language="javascript" src="js/jquery-1.3.2.js"></script>
<script language="javascript" src="js/fun.js"></script>
<body>
<div style="width:200px; height:12px; border:1px solid #0000FF">
  <div id="pg" style="width:0%; height:100%;background-color:#0000FF"></div>
</div>
<br>
<div id="pgtext" style="width:100px; height:20px"></div>
<br>
<input type="button" value="开始" onclick="progress()" />
</body>
</html>

progress.php:

<?php
$file = "./count.txt";
$fp = fopen($file, "r");
$txt = fread($fp, filesize($file));
echo $txt;
$fp1 = fopen($file, "w");
if($txt<100){
  $txt++;
  fwrite($fp1, $txt);
}else{
  fwrite($fp1, 1);
}
fclose($fp1);
fclose($fp);
?>

二 运行结果

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+ajax技巧与应用小结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

相关文章

用PHP获取Google AJAX Search API 数据的代码

http://code.google.com/apis/ajaxsearch/documentation/ 复制代码 代码如下: // This example request incl...

php cli 方式 在crotab中运行解决

复制代码 代码如下: /var/www/html/bt/e/BtSys:.:/usr/share/pear:/usr/share/phpPHP Warning: require(../c...

关于更改Zend Studio/Eclipse代码风格主题的介绍

关于更改Zend Studio/Eclipse代码风格主题的介绍

最近决定把几个IDE的代码样式统一一下,Visual Studio的还算好改,PHP目前用得不多,不过也打算给Zend Studio换身新装。 网上搜索的一些更改Zend Studio主...

php写入文件不覆盖的实例讲解

php写入文件不覆盖的实例讲解

file_put_contents():向文件中写入内容并且不覆盖之前的内容。 步骤: 1、新建文件 2、声明要写入内容的文件 3、这个文件的内容如图 4、file_get_con...

PHP随机生成随机个数的字母组合示例

在很多系统环境下大家都会用到字母组合各种编码,下面推荐大家非常实用的PHP代码。 $num由几个字母组合。 $s字母包含大小写,可以自己调配大写还小写。 复制代码 代码如下: funct...