我有一个类似html的元素:
<div id="el1">Change only me<div>but not me</div></div>
但是我只想更改第一个文本并保留子div不变
document.getElementById("el1").innerText = "changed!"
<div id="el1">Change only me<div>but not me</div></div>
答案 0 :(得分:4)
尝试一下:
import {USER_LOGIN_SUCCESS, SET_SIDEBAR_VISIBILITY} from 'react-admin'
document.getElementById("el1").childNodes[0].textContent = "changed";