MIP.util.dom

    closest

    • 参数:
      • {HTMLElement} element 指定元素
      • {string} selector 选择器
    • 返回值:

      {?HTMLElement}

      匹配的元素节点 或 null

    • 用法:

      检测返回 element 就近的父级 <a> 标签, 没有返回 null

      1. MIP.util.dom.closest(element, 'a')
    • 参数:
      • {HTMLElement} element 指定元素节点
      • {HTMLElement} child 子节点
    • 用法:

      // 判断 element 节点中是否含有传入的 childElement 节点

    closestTo

    • 参数:
      • {HTMLElement} element 指定元素
      • {string} selector 选择器
      • {HTMLElement} target 目标节点
    • {?HTMLElement}

      匹配的元素节点 或 null

    • 用法:

      检测 targetElement 中是否存在,element 的就近父级 <a> 标签,有则返回该 <a>标签,没有返回

      1. MIP.util.dom.closestTo(element, 'a', targetElement)
    • 参数:
      • {HTMLElement} element 指定元素
      • {string} selector 选择器
    • 返回值:

      {boolean}

    • 用法:

      检测 element 元素是否匹配 test 类名

    create

    • 参数:
      • {string} str html 字符串
    • 返回值:

      {?HTMLElement}

    • 用法:

      将 html 字符串创建元素 <span> 节点

      1. // 返回一个 span 元素节点
      2. MIP.util.dom.create('<span><span>1</span></span>')
      3. MIP.util.dom.create('<span>test1</span><span>test2</span>')
      4. // 返回 null
      5. MIP.util.dom.create('1')
    • 参数:
      • {HTMLElement} parent 指定元素节点
      • {Array} children 待插入的子节点列表
    • 返回值:

      {boolean}

    • 用法:

      将 childElement 节点列表依次插入 element 元素节点

    waitDocumentReady

    • 参数:
      • {Function} cb 回调函数
    • 返回值:

      undefined

    • 用法:

      检测 document.body 存在后执行传入的回调函数

      1. MIP.util.dom.waitDocumentReady(function() {