我想知道如何只能刷新网站中的特定元素,而不刷新整个网页吗?我正在谈论的元素是Flash应用程序,加载速度非常慢,并且可能会遇到连接超时。我想让用户仅刷新该元素/ falsh应用程序。我怎么做?下面,我有一个Ajax函数,该函数可以更新HTML元素,但不确定如何将其应用于我的情况。
<head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "ajax_info.txt", true); xmlhttp.send(); } </script> </head> <body> <div id="myDiv"> <h2>Let AJAX change this text</h2> </div> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body>
试试这个:
function reload(){ var container = document.getElementById("yourDiv"); var content = container.innerHTML; container.innerHTML= content; //this line is to watch the result in console , you can remove it later console.log("Refreshed"); } <a href="javascript: reload()">Click to Reload</a> <div id="yourDiv">The content that you want to refresh/reload</div>
希望它能工作。让我知道