相关疑难解决方法(0)

textContent与innerText之间的区别

textContentinnerTextJavaScript有什么区别?

我可以使用textContent如下:

var logo$ = document.getElementsByClassName('logo')[0];
logo$.textContent = "Example";
Run Code Online (Sandbox Code Playgroud)

javascript

119
推荐指数
7
解决办法
4万
查看次数

使用innerHTML,安全问题是什么?

有人告诉我在我的 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)

html javascript security xss innerhtml

6
推荐指数
1
解决办法
3770
查看次数

标签 统计

javascript ×2

html ×1

innerhtml ×1

security ×1

xss ×1