How to refresh a div?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 15:04:29

问题


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.


回答1:


With AJAX.

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




回答2:


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.




回答3:


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




回答4:


<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);


来源:https://stackoverflow.com/questions/11448791/how-to-refresh-a-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!