[英]How to get innerHTML content from a loaded element made by .load()
这里是
part.html:
<div id="header">
Hello Mars
</div>
full.html:
<div id="inj">
</div>
$('#inj').load("part.html #header");
alert(document.getElementById("header").innerHTML); <-- this part is not working
如果要检查已加载的内容,则需要执行以下操作:
$('#inj').load("part.html #header",function(){
alert(document.getElementById("header").innerHTML);
});
load命令是异步的,您必须等待内容加载后才能读取。
load
可以具有在请求完成时执行的回调函数参数。
$('#inj').load('part.html', function() {
alert(document.getElementById('inj').innerHTML);
});
或者由于您使用的是jQuery而不是getElementById
:
$('#inj').html()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.