javascript - 如何更改加载到其他 html 的 body 标记内的 html 内容

标签 javascript jquery html

我正在另一个html页面中加载一个html页面,比如说,home.htmlindex.html内部调用,但现在我想更改的一些内容>home.html 借助 index.html 内的 java 脚本或 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>

最佳答案

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

类似于:

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

关于javascript - 如何更改加载到其他 html 的 body 标记内的 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47323839/

相关文章:

javascript - 如果在 php 和 javascript 的帮助下提交为空白,如何更改输入文本颜色?

javascript - 显示第1页,直到第2页dom完全创建

javascript - 填写表单时不会启用提交按钮

javascript - 如何检查一个元素是否是主体?

javascript - 使用 Javascript 检查文件夹中是否存在文件

javascript - 使用 Javascript 在 MongoDB 中执行带有希腊字符的查询不返回任何结果

javascript - 如何使用 jQuery 从 css 控制动画时间

javascript - 使用全局变量存储数字 (JavaScript)

javascript - 在 Google Apps 脚本中获取今天的日期

javascript - <tspan> text </tspan> 如果未定义 id 或 class,如何删除文本?