Predict textContent 更新
预测输出 简单
题目
如果 HTML 有 `<p id='msg'>旧</p>`, 什么做 page show 之后这个 code 运行?
代码
const el = document.getElementById("msg");
el.textContent = "New";
console.log(el.textContent);
提示
textContent replaces 文本内容的 元素.
解释
设置 el.textContent = "新" replaces all text content of the element with "新". The paragraph that showed 'Old' now shows 'New'. Reading el.textContent back returns "新", 哪个是 printed 到 console.
相关资源
相关课程
- DOM
学习关于 textContent.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。