2021/6/9 js基础记忆

'''
一、js基础知识
/*多行注释*/
//单行注释
<script>js代码</script>
<script>如果放在head或者body上面,则需要写入以下代码
window.onload = function (){
js代码
}
</script>
;
二、js基础
var 变量名 = 变量值
let 变量名 = 变量值
const 常量名 = 常量值

number数值类型
不分int、float、进制等
parseInt()
parseFloat()
string字符串类型
'' "" `模板字符串${变量名}`
.length
.trim()
.trimLeft()
.trimRight()
.charAt(index)
.concat(obj)
.indexOf(str, start)
.substring(start, end)
.slice(start, end)
.split('', count)
.toLowerCase()
.toUpperCase()
.match('re')

boolean
true/false
空字符串、0、null、undefined、NaN

null:值为空,可用于赋值给变量,实现清除数据
undefined:变量定义却未初始化赋值,对于没有返回值的函数,也是返回undefined

typeof 变量名 返回该变量的数据类型

+ - * / % ++ --
> >= < <= != == !== ===
弱:先转换为统一的数据类型,再进行比较
强;直接进行比较,数据类型也参与
&& || !
+= -= *= /= %= =

if (){}else {}
if (){}else if (){}
switch (){ case :xxx; break;...;default:xxx;break;}
while (){}
for (;;){}
a > b ? a:b (python: a if a > b else b)

function 函数名() {}
var a = function() {}
(function() {})()
var a = 形参 => 返回值;
arguments属性
全局变量:再全局有效 局部变量:仅函数内部有效
词法分析:
函数参数:存在则作为AO对象的属性,赋值undefined
局部变量:存在则作为AO对象的属性,赋值undefined
函数声明:AO.函数名 = 函数声明


var a = [1,2,3] --> python:collections.deque
.length
.push(obj)
.pop()
.unshift(obj)
.shift()
.reverse()
.slice(start, end)
.splice(index, count, obj)
.join(seq)
.concat(list)
.sort(func)
.forEach(func(value, index, obj), thisValue)
.map(func(value, index, obj), thisValue)

var a = new Object(item)
k 只能是字符串

var a = new Map()
k 可以是任何对象
.set(key, value)
.get(key)
.delete(key)
.has(key)

var a = new Date()
'y/m/d h:m'
'm/d/y h:m'
getTime()
(y,m,d,h,m,s,ms)

.getYear/Month/Date/Hours/Minutes/Seconds/Milliseconds()
.getFullYear()
.getDay()
.getTime()
.toLocaleString()

JSON.parse()
JSON.stringify()

var a = new RegExp('re')
var a = /re/g;
.test(string) true/false
.lastIndex 0

Math对象
.abs()/pow/round/random/min/max/sqrt/sin/tan/log/exp/floor

var a = new FormData()
obj = $(#id).files[0]
a.readAsdataURL(obj)
a.result
a.append(k, v)

三、BOM
window
.innerWidth
.innerHeight
.open('', '', '')
.close()

navigator
.appName
.appVersion
.userAgent
.platform

screen
.availWidth
.availHeight

history
.back()
.forward()

location
.href
.href=""
.reload()

alert('')
confirm('') true/false
prompt('', '') ''

setTimeout()
clearTimeout()
setInterval()
clearInterval()

DOM操作
DOM标准中HTML文档中一切皆为节点node
文档节点 document
元素节点 element
文本节点 text
属性节点 attribute
注释节点 comment

查找标签
document.getElementById('')
document.getElementsByClassName('')
document.getElementsByTagName('')

.parentElement
.children
.firstElementChild
.lastElementChild
.nextElementSibling
.previousElementSibling

.createElement('')
.appendChild(create)
.insertBefore(create, 节点)
.innerText="xxx"

.removeChild()
.replaceChild(new_create, old)

.innerText
.innerHTML

.属性名
.value
.files

.classList
.add('')
.remove('')
.contains('')
.toggle('')

.style
.样式名 = ""

事件
onclick
ondblclick

onfocus
onblur

onchange
onselect

onkeydown
onkeyup
onkeypress

onmousedown
onmouseover
onmouseout
onmousemove

onload
onsubmit



'''

posted @ 2021-06-09 22:34  zzwYYYYYY  阅读(79)  评论(0)    收藏  举报