博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使用insertAdjacentHTML
阅读量:2506 次
发布时间:2019-05-11

本文共 1084 字,大约阅读时间需要 3 分钟。

insertAdjacentHTML is a very cool DOM method we can call on any DOM element to add new content to a page.

insertAdjacentHTML是一个非常酷的DOM方法,我们可以调用任何DOM元素来向页面添加新内容。

It is a nice and flexible way to insert new content.

这是一种插入新内容的好方法。

The method is called on an element and accepts 2 parameters: the position, and a string containing HTML.

该方法在一个元素上调用,并接受2个参数:position和一个包含HTML的字符串。

Here’s an example:

这是一个例子:

const item = `
test
`document.querySelector('#container').insertAdjacentHTML('afterend', item)

Notice the afterend string.

注意afterend字符串。

This represents the position we’re going to add the HTML into the container.

这代表了我们将HTML添加到容器中的位置。

We have 4 possible positions:

我们有4个可能的职位:

  • beforebegin before the element

    在元素之前beforebegin

  • afterbegin before the first children of the element

    在元素的第一afterbegin元素之前开始

  • beforeend after the last children of the element

    beforeend的最后一个子元素之后的beforeend

  • afterend after the element

    afterend元素后

Here’s how we would add a new item to a list:

这是我们将新项目添加到列表的方法:

document.querySelector('ul').insertAdjacentHTML('beforeend', '
  • item
  • ')

    翻译自:

    转载地址:http://hxmgb.baihongyu.com/

    你可能感兴趣的文章
    “此人不存在”
    查看>>
    github.com加速节点
    查看>>
    解密zend-PHP凤凰源码程序
    查看>>
    python3 序列分片记录
    查看>>
    Atitit.git的存储结构and 追踪
    查看>>
    atitit 读书与获取知识资料的attilax的总结.docx
    查看>>
    B站 React教程笔记day2(3)React-Redux
    查看>>
    找了一个api管理工具
    查看>>
    C++——string类和标准模板库
    查看>>
    zt C++ list 类学习笔记
    查看>>
    git常用命令
    查看>>
    探讨和比较Java和_NET的序列化_Serialization_框架
    查看>>
    1、jQuery概述
    查看>>
    Object 一些方法
    查看>>
    数组比较大小的几种方法及math是方法
    查看>>
    FTP站点建立 普通电脑版&&服务器版
    查看>>
    js 给一段代码,给出运行后的最终结果的一些综合情况、
    查看>>
    webservice 详解
    查看>>
    js自动补全实例
    查看>>
    VS无法启动调试:“生成下面的模块时,启用了优化或没有调试信息“
    查看>>