用ajax怎么做从1到100的单个数字自动变换,就跟时间自动刷新一样,如一开始是1,然后变成2.。。最后100,循环,

解决方案 »

  1.   

    这个跟ajax有什么关系?
      

  2.   

    js 
    window.setInterval("test()",1000);//每秒调用一次test()方法
    至于你在test 方法里面做不做ajax就是你的事了
      

  3.   


    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <meta charset="utf-8">
      <title>JS Bin</title>
      <script>
        window.onload = function(){
       
          window.setInterval("test()",1000);
        }
    var i = 0;
    function test(){
    i++;
       alert(i);
    }
      </script>
      
    </head>
    <body></body>
    </html>
      

  4.   

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <meta charset="utf-8">
      <title>JS Bin</title>
      <script>
        window.onload = function(){     
                window.setInterval("test()",1000);
        }
        var i = 0;
        function test(){
             if(i>=0 && i<=100)
             { 
               i++;
              alert(i);
             }
        }
      </script>
       
    </head>
    <body>
     
    </body>
    </html>
      

  5.   

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <meta charset="utf-8">
      <title>JS Bin</title>
      <script>
        window.onload = function(){     
                window.setInterval("test()",1000);
        }
        var i = 0;
        function test(){
             if(i>=0 && i<100)
             { 
               i++;
              alert(i);
             }
        }
      </script>
       
    </head>
    <body>
     
    </body>
    </html> 
      

  6.   

    完整例子<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
     </head> <body>
      <div id="show"></div>
      <script type="text/javascript">
      var num = 0;
      var et = setInterval(function(){
    num++;
    if(num>100){
    clearInterval(et);
    }else{
    document.getElementById('show').innerHTML = num;
    }
      },100)
      </script>
     </body>
    </html>
      

  7.   

    有没有““ php+ajax”” 相结合来实现这个功能的,简单详细点的,大神赐教…
      

  8.   


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Refresh" content="1"/>
    <title>hehe</title>
    <style>
    .count{
       border:1px solid #7e7474;
       width:500px;
       height:500px;
       margin:0px auto;
       text-align:center;
       line-height:500px;
       background:#f0f0f0;
       font-size:48px;
    }
    #math{font-size:42px;text-shadow: 0 -1px 0 #72a441;color:#360;font-weight:700;}
    </style>
    <script src="./jquery-1.8.3.min.js" type="text/javascript"></script> 
    <script>
    function magic_number(value) { 
        var num = $("#math"); 
        num.animate({count: value}, { //从一个数字到另一个数字变换
            duration: 500, 
            step: function() { 
                num.text(String(parseInt(this.count))); 
            } 
        }); 
    }; 
    function update() { //向后台发送ajax请求
        $.getJSON("mathnum.php?jsonp=?", function(data) { 
            magic_number(data.n); 
        }); 
    }; 
    setInterval(update, 1000); //执行1秒刷新一次
    update();
    </script>
    </head>
    <body>
    <div  class="count" ><span id="math"></span></div>
    </body>
    </html><?php
    $total_data = array( 
        'n' => rand(0,999) //随机数
    );     
    echo $_GET['jsonp'].'('. json_encode($total_data) . ')'; 
    echo "<hr/>";
    ?>
    上面的代码输出是随机的数,我想更改为数字动态累加,
    就是输出从1开始++,然后是2,3,……在同位置到另一个数的变换循环,
    哪里需要更改的地方,大神…
      

  9.   

    基础代码<?php
    if($_POST) {
      echo $_POST['last']+1; //将传入的数字加一后返回
      exit;
    }
    ?>
    <script src="scripts/jquery-1.8.3.min.js"></script> 
    <script>
    $(function() {
      function update() { //向后台发送ajax请求
        $('#math').load(location.href, { last : $('#math').html()});
      }; 
      setInterval(update, 1000); //执行1秒刷新一次
      update();
    });
    </script>
    <span id="math"></span>
      

  10.   

    大神,为什么我这里没有效果啊,服务器都开了呀。那还可以用其它的方法要用到php+ajax请求的,各大神支下小白我……
      

  11.   

    <script src="scripts/jquery-1.8.3.min.js"></script> 
    总要按你的改改吧
      

  12.   

    代码还是上面的,再帮我改改,不要随机数字,就改成 php+ajax 实现数字累加功能,1开始,2,3…100循环又1开始,这样的,能ok嘛,求教大神,