Detailed JavaScript syntax (DOM && BOM)

Attention: JavaScript = ECMAScript scripting language standards + JavaScript own unique things (GOOD + DOM)

One, BOM: Browser Object Model Browser Object Model

two, DOM: Document Object Model Document Object Model

一, GOOD:

1. Concept: Browser Object Model Browser Object Model

* The various components of the package browser into an object.

2. Composition:

* Window: window object

* Navigator: Object Browser

* Screen: Display screen objects

* History: history object

* Location: Address Object bar

3. Window: window object

    1. 创建
    2. 方法
         1. 与弹出框有关的方法:
            alert()	显示带有一段消息和一个确认按钮的警告框。
            confirm()	显示带有一段消息以及确认按钮和取消按钮的对话框。
                * 如果用户点击确定按钮,则方法返回true
                * 如果用户点击取消按钮,则方法返回false
            prompt()	显示可提示用户输入的对话框。
                * 返回值:获取用户输入的值
         2. 与打开关闭有关的方法:
            close()	关闭浏览器窗口。
                * 谁调用我 ,我关谁
            open()	打开一个新的浏览器窗口
                * 返回新的Window对象
         3. 与定时器有关的方式
            setTimeout()	在指定的毫秒数后调用函数或计算表达式。
                * 参数:
                    1. js代码或者方法对象
                    2. 毫秒值
                * 返回值:唯一标识,用于取消定时器
            clearTimeout()	取消由 setTimeout() 方法设置的 timeout。

            setInterval()	按照指定的周期(以毫秒计)来调用函数或计算表达式。
            clearInterval()	取消由 setInterval() 设置的 timeout。

    3. 属性:
        1. 获取其他BOM对象:
            history
            location
            Navigator
            Screen:
        2. 获取DOM对象
            document
    4. 特点
        * Window对象不需要创建可以直接使用 window使用。 window.方法名();
        * window引用可以省略。  方法名();

4. Location: Address Object bar

1. Create (acquisition):

		1. window.location
		2. location

2. Method:

		* reload()	重新加载当前文档。刷新

3. Properties

		* href	设置或返回完整的 URL。

5. History: history object

    1. 创建(获取):
        1. window.history
        2. history

    2. 方法:
        * back()	加载 history 列表中的前一个 URL。
        * forward()	加载 history 列表中的下一个 URL。
        * go(参数)	加载 history 列表中的某个具体页面。
            * 参数:
                * 正数:前进几个历史记录
                * 负数:后退几个历史记录
    3. 属性:
        * length	返回当前窗口历史列表中的 URL 数量。

Two, DOM:

* The concept: Document Object Model Document Object Model

* The various components of the markup language document, encapsulated as an object. You can use these objects, a markup language document CRUD dynamic operation

* W3C DOM standard is divided into three distinct parts:

* Core DOM - standard model for any structured document

		* Document:文档对象
		* Element:元素对象
		* Attribute:属性对象
		* Text:文本对象
		* Comment:注释对象

		* Node:节点对象,其他5个的父对象

* XML DOM - standard model for XML documents

* HTML DOM - standard model for HTML documents

* Core DOM model:

* Document: Document Object

		1. 创建(获取):在html dom模型中可以使用window对象来获取
			1. window.document
			2. document
		2. 方法:
			1. 获取Element对象:
				1. getElementById()	: 根据id属性值获取元素对象。id属性值一般唯一
				2. getElementsByTagName():根据元素名称获取元素对象们。返回值是一个数组
				3. getElementsByClassName():根据Class属性值获取元素对象们。返回值是一个数组
				4. getElementsByName(): 根据name属性值获取元素对象们。返回值是一个数组
			2. 创建其他DOM对象:
				createAttribute(name)
            	createComment()
            	createElement()
            	createTextNode()
		3. 属性

* Element: element object

		1. 获取/创建:通过document来获取和创建
		2. 方法:
			1. removeAttribute():删除属性
			2. setAttribute():设置属性

* Node: node object, the parent object of the other five

		* 特点:所有dom对象都可以被认为是一个节点
		* 方法:
			* CRUD dom树:
				* appendChild():向节点的子节点列表的结尾添加新的子节点。
				* removeChild()	:删除(并返回)当前节点的指定子节点。
				* replaceChild():用新节点替换一个子节点。
		* 属性:
			* parentNode 返回节点的父节点。

* HTML DOM

1. The set and get the body of the tag: innerHTML

2. Use the html element object's properties

3. Control element style

		1. 使用元素的style属性来设置
			如:
				 //修改样式方式1
		        div1.style.border = "1px solid red";
		        div1.style.width = "200px";
		        //font-size--> fontSize
		        div1.style.fontSize = "20px";
		2. 提前定义好类选择器的样式,通过元素的className属性来设置其class属性值。
Published 33 original articles · won praise 31 · views 8685

Guess you like

Origin blog.csdn.net/qq_43230007/article/details/104217228