当前位置:网站首页>JS native common knowledge
JS native common knowledge
2022-07-03 03:54:00 【This is not difficult】
Site support :
JavaScript
obtain DOM
grammar :document.querySelector(" Selectors ")document.querySelectorAll(" Selectors ")document.getElementById("id name ")document.getElementsByClassName("class name ")document.getElementsByTagName(" Tag name ")document.getElementsByName("name name ")
Example :
<body>
<div class="app">
<div class="div"> Limitless swordsman </div>
<div id="wuJin"> Endless blade </div>
</div>
</body>
<script>
var hero= document.querySelector(".div");
var equip = document.getElementById("wuJin");
</script>

Properties of the operation element
1. operation class attribute
adopt
classNameoperationclassattribute .
Example :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>className attribute </title>
<style>
div {
width: 800px; height: 600px; }
.bg-red {
background-color: red; }
.bg-blue {
background-color: blue; }
.border {
border: 5px solid skyblue; }
</style>
</head>
<body>
<div class="bg-red"></div>
</body>
<script type="text/javascript">
// 1. obtain DOM object
var div = document.querySelector('div');
// 2. obtain class attribute
console.log(div.className); // bg-red
// 3. modify class attribute
div.className = 'bg-blue';
// 4. add to class attribute
// div.className += ' border';
// Equate to
div.className = 'bg-blue border';
</script>
</html>
2. operation style style
adopt
styleProperty can only get inline css, Cannot get embedded and external chains css.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>style attribute </title>
<style>
input {
background-color: #abcdef; color: #ffffff; }
</style>
</head>
<body>
<input type="button" style="background-color: #0094ff;" value=" Point me ">
</body>
<script type="text/javascript">
// 1. obtain DOM object
var input = document.querySelector('input');
// 2. obtain style attribute
console.log(input.style);
// 3. Get the current background color of the button
console.log(input.style.backgroundColor);
// 4. Set the background color of the button to yellow
input.style.backgroundColor = 'yellow';
input.style.width = '500px';
// 5. Set the text color of the button to red
input.style.color = 'red';
input.style.transform = 'rotate(45deg)';
</script>
</html>
Operate this article and content
innerText
innerHTML

Registration events
grammar :
onclick = function(){}、addEventListener(eventName, handler, useCapture)
addEventListener When binding events, take out the on Prefix
Event name :
1. Mouse events
onclick Click events
<body>
<div class="app">
<div class="div"> Limitless swordsman </div>
<div id="wuJin"> Endless blade </div>
</div>
</body>
<script>
document.querySelector("#wuJin").onclick = () => {
alert(" Need gold coins 3100!");
};
document.getElementsByClassName("hero").addEventListener("click", () => {
alert(" A critical hit !");
});
</script>
ondblclick Double-click the event onmouseenter( Commonly used )、onmouseover Mouse migration onmouseleave( Commonly used )、onmouseout Mouse removal onmousedown The mouse click onmouseup Release the mouse onmousemove Mouse movement onfocus Get focus onblur Lose focus oninput Input event onchange The drop-down box changes onscroll Scroll bar scroll
2. Loading event
onload Loading complete ( And load successfully )
The compiler parses from top to bottom html Of documents , if js The code is written in body front , It may not be available DOM object .
window.onloadThis event will not be triggered until all the contents on the interface are loaded .
<script>
window.onload = function() {
// natural js Code
}
</script>
onbeforeunload Call before the page closes onunload The page is closed
3. Keyboard events
onkeydown Press the key
→textarea Keyboard events for text fields
onkeypress Press the key to trigger when pressing the key with value
onkeypressPress down Ctrl、Atl、Shift… In this way, the key without value will not trigger .
onkeyup The buttons pop up
// Judge whether the pressed is Enter key
document.onkeyup = function(event){
if (event.keyCode != 13) {
return false;
}
}

this Point to
1. In ordinary functions this
Point to window
2. In the constructor this
When used as a normal function ,this Point to window
coordination new When used as a constructor ,this Point to the instantiated object
3. Methods this
Who calls methods ,this Just point to who
4. In the timer this
Point to window

change this Point to
1. call Method
Function name .call(this New point , Actual parameters 1, Actual parameters 2, Actual parameters …)
2. apply Method
Function name .apply(this New point , Array or pseudo array )
3. bind Method
- Method 1
Function name .bind(this New point ) - Method 2
Function name .bind(this New point , Actual parameters 1, Actual parameters 2, Actual parameters …)
var obj = {
name:" Novice hand " };
function test(num1,num2) {
console.log(this);
console.log(num1+num2);
}
test(1,2); // this Point to window
// change this Point to , Make it point to obj
test.call(obj,10,20);
test.apply(obj,[10,20]);
var fn = test.bind(obj);
fn(10,20);
var fn = test.bind(obj,10,20);
fn();
bind Will not execute the function , Still call .

Layout
1. Elastic layout
1.1. Purpose
Let the child elements be displayed on one line .
1.2. Writing position
Elastic properties { display: flex; } Set to parent element .
{ display: flex; }Default Stretch without line breaks .
Line break :flex-warp: warp;
1.3. Spindle direction
The main axis and side axis of the elastic box are perpendicular to each other .
By default :
1.4. Change the spindle direction
grammar
flex-direction: value ;
value :
rowFrom left to rightrow-reverseFrom right to leftcolumnFrom top to bottomcolumn-reverseFrom bottom to top
1.5. Alignment mode
1.5.1. Spindle alignment
namely : The arrangement position of sub elements on the spindle .
grammar
justify-content: value ;
value :
flex-startArrange from the starting position of the spindlecenterArranged in the middle of the spindleflex-endArrange from the end of the spindlespace-betweenThe distance between child elements is the same ( Commonly used )space-aroundThe spacing between the left and right of the child elements is the same ( Commonly used )
1.5.2. Side axis alignment
namely : The vertical arrangement position of the child elements in the whole row .
grammar
align-items: value ;
value :
flex-startLean upcentermiddleflex-endDownstretchThe tensile ( By default, the height of the child element will be stretched to fill the parent element . Premise : The child element has no height .)
1.5.3. Multi line element alignment
grammar
align-content: value ;
value :
flex-startcenterflex-endstretchspace-betweenspace-around
1.6. Elastic division proportion
grammar
Parent element :display: flex;
Subelement :flex: The number ;
meaning : Set the width of the parent element according to flex In proportion to .
If other sub boxes (a With the exception of ) Have a fixed width , Give the remaining width of the parent box to the child box a, So set it directly a Properties offlex: 1;that will do .

Box shadow
box-shadow: 0px 0px 10px 3px #ccc;
paraphrase :
One sided box shadow
Font shadow
timer 、 Timer
timer
effect : The code is executed every once in a while .
establish :
var timeId = setInterval(handler, interval);
timeId : Unique identification of each timer .
handler: Code to execute , It's a function .
interval: Event interval ( millisecond ).
eliminate :
clearInterval(timeId);
eg:
var homeTime;
document.querySelector('.title').onclick = function(){
clearInterval(homeTime);
homeTime = setInterval(function(){
// do something...
},1000)
}
Timer
effect : The code will be executed once every other time , It will close automatically after execution .
establish :
var timeId = setTimeout(handler, interval);
eliminate :
clearTimeout(timeId);
$nextTick
$nextTick It helps us calculate dom The latest update .
It is setTimeout Advanced version of , It is equivalent to helping us calculate the specific time of data rendering to the page .
eg:
this.$nextTick(() => {
// do something...
})

边栏推荐
- 如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
- 基于Pytorch和RDKit的QSAR模型建立脚本
- 第十届中国云计算大会·中国站:展望未来十年科技走向
- 2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func main() { var a =
- [embedded module] OLED display module
- Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
- The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post
- navicat 导出数据库的表结构
- 在 .NET 6 项目中使用 Startup.cs
- leetcode:297. 二叉树的序列化与反序列化
猜你喜欢

What can learning pytorch do?

CEPH Shangwen network xUP Nange that releases the power of data

简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

毕设-基于SSM宠物领养中心

【刷题篇】多数元素(超级水王问题)

『期末复习』16/32位微处理器(8086)基本寄存器

2022deepbrainchain biweekly report no. 104 (01.16-02.15)

How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo

Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
随机推荐
How does the pytorch project run?
Web session management security issues
Arlo's thinking about himself
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
2022 tea master (primary) examination questions and tea master (primary) examination question bank
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode
【刷题篇】接雨水(一维)
简易版 微信小程序开发之for指令、上传图片及展示效果优化
Pytorch multi card distributed training distributeddataparallel usage
【学习笔记】seckill-秒杀项目--(11)项目总结
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
2022 P cylinder filling examination content and P cylinder filling practice examination video
User value is the last word in the competition of mobile phone market
Error c2694 "void logger:: log (nvinfer1:: ilogger:: severity, const char *)": rewrite the restrictive exception specification of virtual functions than base class virtual member functions
【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】
nodejs基础:浅聊url和querystring模块
[daily question] dichotomy - find a single dog (Bushi)
numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
编译文件时报错:错误: 编码GBK的不可映射字符





