js第六天笔记

2017-07-13  本文已影响0人  固执_i

DOM: document object model

DOM中元素获取的方式

   - tag
   - #id
   - .class
用法:
1.上下文可以是document,也可以是一个元素。
2.参数是选择器,如:"div .className"。
3.返回值只获取到一个元素。

节点

|nodeType | nodeName | nodeValue
---|---|---|---
文本节点 | 3 | "#text" | 文本内容
元素节点 | 1 | 大写的标签 | null
注释节点 | 8 | #comment | 注释内容
document节点|9 | #document | null

节点关系

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>节点常用属性</title>
<style type="text/css">    
    #box1{
        width: 400px; height: 200px;background-color: red;
    }
    #box2{
        width: 200px;height: 200px;background-color: green;
    }
    #box3{
        width: 200px;height: 200px;background-color: yellow;
    }
</style>
</head>
<body>
<div id="box1">
    <p>我是第一个P</p>
    <p>我是第二个P</p>
    <p>我是第三个P</p>
    <p>我是第四个P</p>
    <div>
        <p>我是第1个P</p>
        <p>我是第2个P</p>
        <p>我是第3个P</p>
        <p>我是第4个P</p>
    </div>
</div>
<div id="box2"></div>
<div id="box3"></div>
<input id="put" type="text" name="in" placeholder="sunck is a good man">
</body>
</html>
+ 一般情况兼容,但是在IE7/8下,如果有注释的话,拿到的是不准确的;

封装

上一篇 下一篇

猜你喜欢

热点阅读