javascript - How to refresh a div? - Stack Overflow

Most of the examples I have found explain how to refresh a div with text or with another page. I just w

Most of the examples I have found explain how to refresh a div with text or with another page. I just want to reload the div again after click on a button. How can I do this using javascript?

Thanks.

Most of the examples I have found explain how to refresh a div with text or with another page. I just want to reload the div again after click on a button. How can I do this using javascript?

Thanks.

Share asked Jul 12, 2012 at 9:27 PepeFloydPepeFloyd 1,2053 gold badges14 silver badges28 bronze badges 1
  • What do you mean by refresh a div, you want to place new content in the div? If so, it could be as easy as changing the innerHTML contents. – Wesley Commented Jul 12, 2012 at 9:29
Add a ment  | 

4 Answers 4

Reset to default 2

With AJAX.

If you use jQuery, it's as simple as $('#mydiv').load(url)

Any change to the DIV element is stored in the DOM of the page is displayed immediately. You do not need to do anything for that. However, the old state of the DIV after the change is lost. You need to store it somewhere and setup it again to make it visible.

Please call a ajax function on click of the button and set the innerHTML property of the div with return result.

<script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script>

So we just place this little JS code snippet into our page to refresh everything inside the tag with the content id, let’s say every 5 seconds:

setInterval(function() {
    $("#content").load(location.href,"");
}, 5000);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745070322a4609503.html

相关推荐

  • javascript - How to refresh a div? - Stack Overflow

    Most of the examples I have found explain how to refresh a div with text or with another page. I just w

    16小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信