如何更改加载到其他html的body标签内的html内容

时间:2017-11-16 07:23:54

标签: javascript jquery html

我正在其他地方加载一个html页面,假设home.htmlindex.html内调用,但现在我想在java脚本的帮助下更改home.html的某些内容或index.html内的jquery 以下是我到目前为止所尝试的内容

的index.html

   <html>
    <body> </body>
</html>
<script>
    $('body').load('home.html');
    // below div **session_error** is from home.html page,I wanted to change its text on this page
           $('#session_error').html("This is session out errror");

</script>

1 个答案:

答案 0 :(得分:2)

.load()调用是异步的。因此,您需要在进行更改之前等待它完成。

类似的东西:

$('body').load('home.html', function() {
   $('#session_error').html("This is session out errror");
});