文章目录

    这里记录的是在做原生JS练习中一些自己不熟悉的小知识点,并不是系统的原生JS操作,目前这部分还在进行中,以后边练习边补充,算是查漏补缺。

  1. 元素的id target.id

  2. 元素的标签名 target.nodeName

  3. 元素的兄弟元素节点 target.parentNode.children;

  4. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    function hasClass(element, className) {
    return (new RegExp('(\\s|^)' + className + '(\\s|$)')).test(element.className);
    }
    function addClass(element, newClassName) {
    if (!hasClass(element, newClassName)) {
    element.className = element.className ? (element.className + " " + newClassName) : newClassName;
    }
    }
    function removeClass(element, oldClassName) {
    if (hasClass(element, oldClassName)) {
    element.className = element.className.replace(new RegExp('(\\s|^)'+ oldClassName + '(\\s|$)'), " ").trim();
    }
    }
  5. cursor:crosshair; 鼠标光标是十字;

  6. label标签的用法:除了用for属性与指定的表单元素关联外,直接把表单元素包含在label里面也能实现关系。

  7. 清除设置的属性 box.style.cssText =” “;

  8. margin 折叠:

    发生折叠需要时相邻的非浮动元素
    折叠发生在垂直外边距上,即margin-top/margin-bottom;
    折叠后取其中最大的那个margin值作为最终值。
    定义了属性overflow且值不为visible(即创建了新的块级格式化上下文)的块元素,不与它的子元素发生margin 折叠;
    绝对定位元素的 margin 不与任何 margin 发生折叠。
    根元素的 margin 不与其它任何 margin 发生折叠;

  9. parent.childNodes 是所有的子元素
    parent.child 是只有第一层子元素

文章目录