FSWD_2_JavaScript
来源:互联网 发布:阿里云怎么添加监控 编辑:程序博客网 时间:2024/05/29 13:32
- location
- data type
- data structure
- Events
- function
- structure
- debug
JS既在client side有,也在server side 和 database side有。
location
一般情况,js代码可以放在任何位置。
js库一般放在head里面
js代码一般放在body的最后面
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <!-- LOAD JS LIBRARIES HERE --> <scrpit src="mycode.js"></scrpit></head><body><!-- your js code here usually --><script> function surprise() { alert("hello"); }</script></body></html>
data type
number
只有一种表示,可以用科学计数法。
string
boolean
&& || !
object
var
typeof
parseInt
parseFloat
String
data structure
[]
length
join
push
shift
pop
unshift
concat
var a = [1,2,3];var a = new Array(3);array.join(separator)array.lengtharray.pusharray.poparray.shiftarray.unshiftarray1.concat(array2)
Events
onload is triggered when the object is loaded.
<body onload="alert('hello'); alert('hello2')">
function
alert
confirm
prompt
isNaN
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body><script> alert("alert"); confirm("confirm"); var user_name; user_name = prompt("what's your name"); document.write("welcome to my page " + user_name +"!");</script></body></html>
random
Math.random
Math.floor
Math.random()*max_value #[0,max_value)
function
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <script> function user_age() { age = prompt("input your age"); return parseInt(age) } function check_age() { if (user_age() < 18) alert("go out") } </script></head><body onload="check_age()"></body></html>
structure
if else
switch break
while () {};
string.indexof(“text”) location of “text”
do {} while(); does the once at least
local and global variable
如果在函数里面使用了没有被var创建的变量a,a会变成全局变量。
debug
使用chrome中的开发者工具
同时可以在console中输入js代码
console.log()与alert()的区别是用户不可见但是开发者可见。
0 0