动态获取特定div网页中的网页

时间:2018-02-14 08:08:58

标签: javascript html ajax jsp

我有一个网页,我想要点击链接或按钮;特定div网页的内容得到更新,并替换为我在其他html页面中编写的内容。怎么做?

1 个答案:

答案 0 :(得分:0)

有几种方法可以做到这一点。

<script>
function loaddata()
{ 
var xhr = new XMLHttpRequest();
xhr.open("GET","page.html",true);
xhr.onload = function(){
if(this.readyState === 4)
{ 
var div = document.getElementById("divid"); // the div where you want to load the data 
div.innerHTML = this.responseText;
}
}
xhr.send();
}
</script>

html代码

<button onclick="loaddata()">click</button>
<div id="divid"></div>

还有其他方法可以做到这一点。但我只显示了一个javascript 希望这可以帮助你找到你想要的东西