Javascript 笔记
1. 命名规则
(1)对象:大驼峰
(2)变量和函数:小驼峰
(3)常量:大写
2. 类型转换
Text to Number:
parseInt()、parseFloat()
3. style
网页上所有元素都有一个style对象, width、height都是样式
4. 作用域(scope)
全局:
函数:
5. 回调函数
被外部调用,以响应外部事件
被浏览器调用:
<body onload="foo()">
window.onload = function(){}
被外部JS脚本调用
6. 每个表单域都有一个 form 对象
<input type="text" name="zipcode" id="zipcode" size="5" onclick="showMe(this.form)" />
...
function showMe(theForm) {
var value = theForm["zipcode"].value;
}
7. 修改样式
document.getElementById("ID").className
document.getElementById("ID").style.
8. 面向对象
function Blog(body, date) { // 每个对象均有一个副本 // 属性 this.date = date; this.body = body; // 方法 this.localFunc = function() {} } // 方法,类所有,只有一份副本 Blog.prototype.toString = function() { return this.date + this.body; } // 静态方法 ,通过类名访问 Blog.staticFunc = function() {} // 静态属性,通过类名访问 (类的方法通过this.count访问) Blog.signature = "vince"; var blog = new Blog("123", "345"); alert(blog.toString()); alert(Blog.signature);
同理,可扩展标准对象
9. 转义符 \
把 \ 后的字符当成普通字符,而不是特殊字符
10. ml
markup language(标记语言)
Final.内置函数
(1)toFixed(num) : 四舍五入到小数点后num位
(2)isNaN() : 判断变量是否为数字
(3) Array对象方法
排序
function compare() {}
Array.sort(compare);
(4)String对象方法
indexOf、charAt、length、toLowerCase、toUpperCase
(5)Math对象
浙公网安备 33010602011771号