weixin_33716941 2014-04-24 07:38 采纳率: 0%
浏览 30

我需要用ajax做到这一点

<style>
    #number{height: 50px; color: #000; }
    </style>


Progress: <div id="number"> </div>
<script type="text/javascript">

    var i = 0;
    d = 1;
function increment(d) {
    if(i<100){
        i+=d;
        document.getElementById('number').innerHTML = i + '&#037;';
    }
    else{
        document.getElementById('number').innerHTML = 'done' ;
    }

}

setInterval('increment(d)', 1000);

</script>

<button type="button" id="button" onclick="d++">Add</button>
<button type="button" onclick="window.location.reload()">Refresh</button>

i'm currently working on a web app with visual studio on asp.net mvc 4. i need to make a partial view that shows a counter that goes from 1 to 100. i added a button that increases by 1 the counter value on every click and another one for refreshing the page. how can i do this using ajax?

  • 写回答

1条回答 默认 最新

  • weixin_33694620 2014-04-24 07:46
    关注

    AJAX (Asynchronous Javascript and XML) is for making web requests without visible page refreshes. That is not what you should be using this for. You can do this using setTimeout. I have provided a JSFiddle for you to use.

    The important bits

    In Javascript, you can simulate asynchronous functionality using setTimeout. This function will allow the Javascript to continue executing, and after a given waiting period, will execute the code you provide.

    function doSomething() { alert("hello"); }
    
    setTimeout(doSomething, 1000);
    

    This will execute the doSomething() method.

    NOTE: You pass the function as a callback. As in doSomething and not doSomething().

    评论

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?