window.onkeydown = function(e) {
console.log(e);
console.log(e.keyCode);
}
var x = 0;
var y = ‘12’ + x + “12”;
var z = true;
if(x) {
console.log(“true”);
} else{
console.log(“false”);
}
var arr1 = new Array(3); [undefined,undefined,undefined]
var arr2 = new Array(1,2,3); [1,2,3]
var arr3 = [1,2,3];
function 函数名(参数1,参数2) {
return 1;
}
var 函数名 = function(参数1,参数2) {
return 1;
}
var rs = 函数名(参数1,参数2);*/
/*var obj = {
name : "zhangsan",
age : "18",
add : function() {
return this.name;
}
}
obj.name
obj[age]*/
传输数据的格式 js—>java java—>js
var json = {
“name” : “zhangsan”,
“age” : “18”
}
String—>Array split()
Array—>String join(“”)
Date
Math
Math.random(); [0,1)
Math.ceil();
Math.floor();
var x = 10;
if(x < 3) {
} else if(x >=3 && x <=5) {
} else if(x > 5 && x <=8) {
} else {
}
switch(i) {
case 1:
...
break;
case 2:
...
break;
case 3:
...
break;
default:
....
break;
}
while(i < 10) {
…
i++;
}
do{
...
i++;
} while(i < 10)
for(var i = 0; i < 5; i++) {
...
}
DOM
html
1.添加/删除/替换<标签>
2.改标签里的属性
css
1.修改样式
节点关系—->上下左右
parentNode()
ul.children() 个数有可能大于0 [
previousElementSibling()
nextElementSibling()*/
查找
var divs = document.getElementsByClassName(“red”);
console.log(divs);
创建
var div = document.createElement(“div”);
div.innerText = “11”;
div.innerHTML = “11“;
插入
父元素.appendChild(子元素);
父元素.insertBefore(要插入的子元素,插入哪个子元素之前);*/
删除
要删除的元素.remove();*/
替换
父元素.replaceChild(用来替换的新节点,将要被替换的节点);*/
属性
id.type = “password”;
id.getAttribute(“data-test”);
id.setAttribute(“data-t”,”true”);
class属性里添加或删除
/*id.classList.add(“h”);
id.classList.remove(“h”);
id.style.width = “100px”;
id.style.backgroundColor = “yellow”;
id.setAttribute(“style”,”color:blue”);
id.style.setProperty(“background-color”,”blue”);