gpt4 book ai didi

Javascript 没有将另一个页面加载到 DIV 中

转载 作者:行者123 更新时间:2023-11-30 10:25:49 24 4
gpt4 key购买 nike

我今天遇到了一些麻烦。我正在尝试让 Javascript 将内容加载到 <div> 中.现在,这是我的 JavaScript 源代码:

function loadXMLDoc(filename) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
after_load_function(xmlhttp.responseText);
}
}
xmlhttp.open("GET", filename, true);
xmlhttp.send();
}

function after_load_function(responseText) {
document.getElementById("right").innerHTML = responseText;
}

window.onload = function () {
loadXMLDoc("welcome.html");
}

还有我的 div:

<div id="right"></div>

有人知道这个问题吗?

最佳答案

您有什么理由不使用像 JQuery load 这样的抽象 method

$( document ).ready(function() {
$("#right").load( "welcome.html" );
})

我觉得还不错。

关于Javascript 没有将另一个页面加载到 DIV 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19614158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com