reactjs - 如何在同一组件内由 React 组件渲染的 DOM 中替换一组 html 元素代替子元素
问题描述
我想通过反应组件替换一组元素说“..”来代替已经呈现的 DOM 中存在的元素。假设 React 渲染的 html 如下
<p>This is a demo</p>
<div id='1'>Hello<div id='2'><div id='3'>I want to replace this third div with another set of element</div></div></div>
请指导我如何使这成为可能。提前致谢!
解决方案
您可以使用ReactDOM.render()替换或更新元素。
- https://codepen.io/vliumang/pen/XWjGVev
或者直接通过id改变div:
document.getElementById("3").innerHTML = "New text!";
BR
推荐阅读
- c# - 基于相同的密钥在 Kafka 中加入/分组多个主题
- python - 如何定义folium颜色图位置
- java - 在 java spring hibernate 3.6.3 中,如何告诉方法等到锁被获取以及如何重试失败的事务?
- javascript - 如果我按下 Windows aka 开始按钮,如何暂停视频,就像打开新选项卡时此代码如何暂停视频一样?
- html - 如何使用 Angular 6 在 mat-select 中获取下拉文本
- javascript - 无法在jquery中触发onclick事件
- javascript - 覆盖基础更少的属性 UI5
- hibernate - 休眠警告 - 在内存中应用!- 在引擎盖下?什么样的记忆?
- c++ - GDB C++ 如何停止进入标准库
- ruby-on-rails - AnyCable : 在 ROR App 上检索信息 gRPC 信息