textContent和innerTextJavaScript有什么区别?
我可以使用textContent如下:
var logo$ = document.getElementsByClassName('logo')[0];
logo$.textContent = "Example";
Run Code Online (Sandbox Code Playgroud) 有人告诉我在我的 JS 代码中使用 innerHTML 是危险的。我确实明白为什么,但是有人能告诉我这两种使用方式之间是否有区别吗?
第一的:
const onePersonArticle = create('article');
onePersonArticle.className = 'one-person';
const content = ` <label class='info-labels' for="name">NAME: </label><label id='name' class='data-labels'>${member.name}</label>
<label class='info-labels' for="phone">PHONE: </label><label id='phone' class='data-labels'>${member.phone}</label>
<label class='info-labels' for="code-wars">CODEWARS: </label><label id='code-wars' class='data-labels'>${member.cwb} - ${member.cwa}</label>
<label class='info-labels' for="free-code-camp">FREECODECAMP: </label><label id='free-code-camp' class='data-labels'>${member.fccb} - ${member.fcca}</label>
<label class='info-labels' for="notes">NOTES: </label><label id='notes' class='data-labels'>${member.notes}</label>
<span class="person-buttons"><button type="button" name="button" class="button delete-button">?</button>
<button type="button" name="button" class="button edit-button">?</button></span>`;
onePersonArticle.innerHTML = content;
Run Code Online (Sandbox Code Playgroud)
第二:
const onePersonArticle = create('article');
onePersonArticle.className = 'one-person';
onePersonArticle.innerHTML =
` <label class='info-labels' for="name">NAME: </label><label …Run Code Online (Sandbox Code Playgroud)