Reference
网页的动作语言
Examples are better than 1000 words.——一例胜千言
引用
<head></head>
<body></body>
<script></script>
输出
innerHTML
document.write()
window.alert()
console.log()
print()
控制
getElementById("demo")
getElementsByClassName("demo")
getElementsByTagName("p")
querySelectorAll("p.intro")
声明
var
let
cost
注释
//单行注释
/*多行注释*/
运算符
+
-
*
**
/
%
++
--
&&
||
!
==
===
!=
!==
>
<
>=
<=
?
+=
-=
*=
/=
%=
**=
函数
数组:x = ["a","b","c"]
物体:x={name:"fiat",model:"modern",color:"white"}
字符串处理
.length
indexOf()
lastIndexOf()
search()
slice()
substring()
substr()
replace()
toUpperCase()
toLowerCase()
concat()
trim()
charAt()
charCodeAt()
split()
数字
Js语法中,支持数位是15位,以及小数点后17位。
NaN = not a number
isNaN()
数字进制
数字变成物体
toExponential()
toFixed()
toPrecision()
数组
array.foreach()
array.push()
array.pop()
typeof.array
array.join("*")
array.shift()
array.unshift()
delete array[0]
array.splice(2,0,"apple","orange")
array.concat(array)
sort()
reverse()
调用
时间
Date(year, month, day, hours, minutes, seconds, milliseconds)
toUTCString()
toISOString()
toDateString()
getFullYear()
Get the year as a four digit number (yyyy)
getMonth()
Get the month as a number (0-11)
getDate()
Get the day as a number (1-31)
getHours()
Get the hour (0-23)
getMinutes()
Get the minute (0-59)
getSeconds()
Get the second (0-59)
getMilliseconds()
Get the millisecond (0-999)
getTime()
Get the time (milliseconds since January 1, 1970)
getDay()
Get the weekday as a number (0-6)
Date.now()
Get the time. ECMAScript 5.
Method
Description
getUTCDate()
Same as getDate(), but returns the UTC date
getUTCDay()
Same as getDay(), but returns the UTC day
getUTCFullYear()
Same as getFullYear(), but returns the UTC year
getUTCHours()
Same as getHours(), but returns the UTC hour
getUTCMilliseconds()
Same as getMilliseconds(), but returns the UTC milliseconds
getUTCMinutes()
Same as getMinutes(), but returns the UTC minutes
getUTCMonth()
Same as getMonth(), but returns the UTC month
getUTCSeconds()
Same as getSeconds(), but returns the UTC seconds
Method
Description
setDate()
Set the day as a number (1-31)
setFullYear()
Set the year (optionally month and day)
setHours()
Set the hour (0-23)
setMilliseconds()
Set the milliseconds (0-999)
setMinutes()
Set the minutes (0-59)
setMonth()
Set the month (0-11)
setSeconds()
Set the seconds (0-59)
setTime()
Set the time (milliseconds since January 1, 1970)
数学
Math.PI
Math.round()
Math.pow()
Math.sqrt()
Math.abs()
Math.ceil()
Math.floor()
Math.sin()
Math.cos()
Math.min()
Math.max()
Math.random()
Math.E
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
逻辑
逻辑
True or False
Boolean()
variablename = (condition) ? value1:value2
Last updated
Was this helpful?