Dex*_*der 9 html javascript ajax
我想知道如何只刷新我网站中的特定元素,而不是整个网页?我正在谈论的元素是一个加载非常慢的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>
Run Code Online (Sandbox Code Playgroud)
Dex*_*ave 18
试试这个:
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");
}Run Code Online (Sandbox Code Playgroud)
<a href="javascript: reload()">Click to Reload</a>
<div id="yourDiv">The content that you want to refresh/reload</div>Run Code Online (Sandbox Code Playgroud)
希望它有效.让我知道
尝试创建一个运行此命令的 JavaScript 函数:
document.getElementById("youriframeid").contentWindow.location.reload(true);
Run Code Online (Sandbox Code Playgroud)
或者可以使用 HTML 解决方法:
<html>
<body>
<center>
<a href="pagename.htm" target="middle">Refresh iframe</a>
<p>
<iframe src="pagename.htm" name="middle">
</p>
</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
两者可能都是您正在寻找的......
| 归档时间: |
|
| 查看次数: |
95502 次 |
| 最近记录: |