js

语法

定义变量要用var但不声明类型
{}代码块
注释同c++
运算符基本同c++
for循环if语句同c++
[]同python, 从0开始存
小写字母开头的驼峰式命名
typeof返回对象的类型,返回值为带有双引号的字符串

数组

.length长度
.join(str)类似py的join函数
pop(),push(x)

对象

var cls {
    a:1,
    b:2,
    c:"efg",
    d:function() { // = function d() {}
        return this.a + this.b; //this
    }
}

与html联系

html中写<script src=""></script>
js中写:
document.getElementById(id)
设置属性 如.style.background = "rgb(r,g,b)"
firstChild访问第一个儿子

alert(str)警告框
confirm(str)确认框
prompt(str)提词框

jquery操作文件

$('selector').load(path)将文件内容加载
.css()设置style
.html()设置innerHTML
.parent() .children() .prev() .next()父子前后
.remove()删除点前面的那个元素

原文地址:https://www.cnblogs.com/acha/p/11136753.html