当前位置:网站首页>Web APIs (get element event basic operation element)
Web APIs (get element event basic operation element)
2022-07-25 11:47:00 【c_ perfectworld】
API( Application programming interface )
It's some Predefine Function of , The purpose is to provide the ability for applications and developers to access a set of routines based on certain software or hardware , and also No need to access the source code , Or understand the details of the internal working mechanism
Simple understanding : A tool for programmers , In order to realize a certain function
Web API
It's a set provided by the browser Operating browser functions and Page elements Of API(BOM and DOM)
API and Web API summary
- API It is a Interface , Help us To achieve a function , Just use it , No need to tangle inside How to achieve
- Web API Mainly for browser Provided Interface , Mainly for browser do Interaction effect
- Web API Generally there are Input and Output ( Function parameters and return values ),Web API A lot of them are methods ( function )
DOM( Document object model ) Extensible markup language (HTML or XML) Standard programming interface
W3C A series has been defined DOM Interface , adopt DOM Interface Sure Change the content of the page 、 Structure and pattern
DOM Trees
- file : A page is a document ,DOM of use document Express
- Elements : All tags in the page are elements ,DOM Use in element Express
- node : Everything in a web page is a node ( label 、 attribute 、 Text 、 notes ),DOM Use in node Express
Be careful :DOM Think of all the above as objects
Get element method
according to ID obtain
Use getElementByld() Method can get the ID The element object of
- Because the document page loads from top to bottom , So we need to Label first , And then script The label is written at the bottom of the label
- get intend get element Elements by adopt Hump nomenclature
- Parameters id yes Case sensitive Of character string
- Back to a Element object
- console.dir() Print the element object we return , Better view the properties and methods inside
Get... According to the tag name
Use getElementsByTagName() Method can return a with the specified tag name A collection of objects
- The return is , Get it A collection of element objects , With Pseudo array Form storage of
- Want to print the objects in turn , Take the form of traversal
- If there is only one page li The return is still in the form of pseudo array
- If there is no such element in the page , Returns an empty pseudo array
Be careful :
- Because what you get is a collection of objects , All the elements we want to operate inside need to be traversed
- obtain Element objects are dynamic It means that the content inside changes ,js Will follow to change dynamically 、
You can also get an element ( Parent element ) All internal child elements with specified tag names
element.getElementsByTagName(' Tag name ')Be careful :
Parent element must be Single object ( You must specify which element object ) The parent element itself is not included in the acquisition
adopt H5 Add a new method to get
document.getElementsByClassName(‘ Class name ’) // Returns the collection of element objects according to the class namedocument.querySelector(‘ Selectors ’) // Returns the first element object... Based on the specified selectorBe careful : Bear in mind , The selector inside needs to be signed
document.querySelectorAll(‘ Selectors ’) // Returns a collection of all objects of the specified element
obtain body Elements
document.bodyobtain html Elements
document.documentElement The basis of the event
JS It gives us the ability to create dynamic pages , Event is Can be JS To detect To the behavior
Simple understanding : Trigger -- Response mechanism
Every element of the web page Can produce some JS event For example, when a user clicks a button to execute an event to perform certain operations
Three elements of the event
- Event source
The event is triggered by
- Event type
How to trigger , What event , For example, mouse click (onclick), Or mouse over , Or press the keyboard
- Event handler
Complete by function assignment
Steps to execute the event
- Get the event source
- Registration events ( The binding event )
- Add event handler ( Take the form of function assignment )
Operational elements
JS Of DOM The operation can change the content of the web page 、 Structure and pattern , You can use DOM Operate the element to change the content attributes in the element
- Change element content
element.innerText Elements can also be added without events
Don't recognize Html label , Nonstandard , Content from start to end , Remove HTML label , At the same time, spaces and line breaks will be removed
element.innerHTML
Can identify Html label ,W3C standard , Everything from the start position to the end position , Include Html label , Keep spaces and wrap
- Attribute operation of common elements
Ideas : Get the elements that need action , The binding event , Change its properties ( Elements . attribute = ‘xxx’)
- Attribute operations of form elements
utilize DOM You can manipulate the attributes of the following form elements :
type,value,checked,selected,disabled( Ban ) eg : btn.disabled = true amount to this.disabled = true this It points to the caller of the event function
- Style property operation
Can pass JS Modify element size 、 Color 、 Location
element . style A property of Inline style operation
There are few styles , Use when the function is simple
Be careful :
JS The style inside adopts the hump naming method such as :fontSize、backgroundColor
JS modify style Style operation , What's produced is the in line style , css High weight
element . className A property of Class name style operation Change the class name of the current element
Suitable for many styles , Complex functions
Be careful :
class Because it's a reserved word , Therefore use className To manipulate the element class name attribute
className Will directly change the element class name , Will override the original class name
If you want to keep the original class name , It can be used this . className = ‘ Original class name New class name ’ Equivalent to multiple class names
边栏推荐
- Understanding: idea uses Scala to write wordcount programs and generate jar packages
- Dynamic planning question 05_ Missile interception
- 动态规划问题03_最大子段和
- Hardware peripherals =maixpy3
- JS常用内置对象 数据类型的分类 传参 堆栈
- 用 Redis 做一个可靠的延迟队列
- SQL注入 Less17(报错注入+子查询)
- Information management system for typical works of urban sculpture (picture sharing system SSM)
- 绘图==PYQT5
- Details of the list of state products that Apple announced to be eligible for the sales tax holiday in the United States
猜你喜欢

【leetcode刷题】
![[MySQL learning 09]](/img/27/2578f320789ed32552d6f69f14a151.png)
[MySQL learning 09]

WIZnet嵌入式以太网技术培训公开课(免费!!!)

SQL injection LESS18 (header injection + error injection)

SQL注入 Less17(报错注入+子查询)

Reflection reflection

基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现

SQL注入 Less18(头部注入+报错注入)

The principle analysis of filter to solve the request parameter garbled code

【mysql学习08】
随机推荐
JS常用内置对象 数据类型的分类 传参 堆栈
微星主板前面板耳机插孔无声音输出问题【已解决】
【mysql学习09】
【mysql学习08】
JS作用域以及预解析
SQL注入 Less18(头部注入+报错注入)
用 Redis 做一个可靠的延迟队列
将字符串转换为数字
Maskgae: masked graph modeling meets graph autoencoders
[dynamic planning] 70. Climbing stairs
JVM performance tuning methods
Information management system for typical works of urban sculpture (picture sharing system SSM)
Leetcode sword finger offer 27. image of binary tree
OneNET平台控制W5500开发板LED灯
Dynamic planning question 05_ Missile interception
小微企业智能名片管理小程序
SQL language (II)
Greedy problem 01_ Activity arrangement problem
ESP8266 使用 DRV8833驱动板驱动N20电机
SQL language (V)