当对象正在加载时,在innerHTML中显示LOADING
Show LOADING in innerHTML while object is being loaded
我有以下JavaScript函数,加载由contacts.php返回的内容到div id contacts-container,这需要很多时间来完成任务。我想在DIV id contacts-container中显示"LOADING.."文本,而内容正在加载。
function load_contacts() {
document.getElementById("contacts-container").innerHTML='<object type="text/html" data="contacts.php" ></object>';
}
我想要纯JavaScript解决方案
再来点JS怎么样?
function load_contacts() {
var el = document.createElement("object"),
target = document.getElementById("contacts-container")
target.innerHTML = "<span>Loading...</span>";
el.onload = function() {
target.firstChild.remove();
}
el.setAttribute("type","text/html");
el.setAttribute("data","contacts.php");
target.appendChild(el);
}
您可以使用ajax。对此,我的建议是,您必须使用Jquery Ajax。例如,
$("#loadingElement").html("Loading");
$.load("#contacts-container",{},"contacts.php",function(){
$("#loadingElement").html("");
});
相关文章:
- 对于Ajax调用,为什么innerHTML没有显示在IE中
- 如何根据点击使用相同的名称标记来显示innerhtml
- 从URL获取JSON数据并使用innerHTML - 如何显示
- 如何使用innerHTML显示多个输出
- javascript中的变量未显示在使用innerHTML的html页面上
- 我的UTC时区函数未使用innerHTML显示在HTML上
- 我可以更新使用 innerhtml 显示的 javascript 变量吗?
- 将text.innerHTML修改为显示/隐藏脚本中的图像
- 在
段落中使用 getElementById.innerHTML 在 Javascript 中显示变量值
- 我想使用 innerHTML 显示变量的值,但我的代码不起作用
- 在循环中使用 innerHTML 无法正确显示 JSON 结果集
- 为什么当我使用Javascript innerHTML调用我的图像时,它没有显示出来
- innerHTML未更新显示
- Innerhtml显示在页面加载而不是点击
- eval(element.innerHTML)显示意外的语法错误
- HTML SSE或PHP SSE . innerhtml显示顺序
- innerHTML显示函数,而不是函数的返回值
- innerHTML 显示文本但不显示 HTML
- 文档innerHTML显示旧的内容,在ajax加载
- 当我迭代图像链接数组并使用innerHTML显示它们时,为什么IMG标记不能工作?