1. 运用 `innerHTML` 特点直接在现有的元素中刺进HTML内容。2. 运用 `createElement` 和 `appendChild` 办法创立新的元素并增加到DOM中。3. 运用 `insertAdjacentHTML` 办法在指定方位刺进HTML。
```javascript// 办法1: 运用innerHTMLfunction addHtmlUsingInnerHtml { var element = document.getElementById; element.innerHTML = htmlContent;}
// 办法2: 运用createElement和appendChildfunction addHtmlUsingCreateElement { var parentElement = document.getElementById; var newElement = document.createElement; newElement.innerHTML = htmlContent; parentElement.appendChild;}
// 办法3: 运用insertAdjacentHTMLfunction addHtmlUsingInsertAdjacentHTML { var element = document.getElementById; element.insertAdjacentHTML;}
// 示例用法addHtmlUsingInnerHtml;
addHtmlUsingCreateElement;
addHtmlUsingInsertAdjacentHTML;```
```javascript
var newDiv = document.createElement(\
未经允许不得转载:全栈博客园 » js增加html标签