1. js变量var 可加可不加
2. alert(str);输出提示
3. document.write(str);
4. 字符串和变量用+连接
5. Array ('' ,'' );数组
6. js对象 obj=new Object();
obj.username='user1' ;
obj.say=function () {
alert('my name is user1' );
}
7. dom对象eleobj=document;
8. json={'' :'' ,'' :'' ,'' :'' }
9. 函数
function say () {
alert(1 );
}
say();
或
say=function () {
alert(1 );
}
say();
10. 变量作用域
全局变量没有var
局部变量有var
11. 变量类型测试
typeof();
arr instanceof Array 测试变量是否是数组
parseInt();强制转整型
parseFloat();强制转浮点型
eval ();执行字符串表达式
Number();转整型
String();转字符串
Boolean();转boolean类型
12. js中前面的对象不用写
Global 对象
window对象
13. json字符串转json对象
v="{'username':'user1','age':'20'}" ;
obj=eval ('(' +v+')' );
alert(obj);
14. 运算符
+-*/%
in (arr=['a' ,'b' ,'c' ];alert(2 in arr);)
instanceof
delete
15. 语法
if (){}else {}
switch (){case 1 : break ;default : break ;}
while (){}
for (){}
forIn遍历
16. 消息框
警告框 alert("" );
确认框 confrim("" );
return false ;阻止默认链接
输入框 r=prompt("" );
17. js内置对象
数学
Math.PI
Math.ceil();
Math.floor();
Math.round();
Math.random();
Math.max(1 ,100 ,2 );
Math.min();
日期
dobj=new Date();
dobj.getFullYear();
getMonth();
getDate();
getHours();
getSeconds();
定时器
设定定时器
sobj=setInterval(function () {
},1000 );
sobj=setInterval(getDate,1000 );
清除定时器
clearInterval(sobj);
location='' ;定位
超时器
tobj=setTimeout(function () { },3000 );
butonid.onclick=function () {
clearTimeout(tobj);
}
字符串
length
indexOf();
lastIndexOf();
substr(1 ,5 );
slice(start,end);
字符串分割成数组
split(reg);
可以查找多个字符并可以用于正则表达式
search(reg);
字符串匹配,查出所有的g是全部i是忽略大小写
match(/home/g);
替换原来的字符串
replace(reg,"str" );
数组对象
length
把数组连成字符串
join("/" )
从数组之后弹出一个值
pop();
从数组最后压入一个值
push();
从数组最前面删除一个元素
shift();
从数组前面压入一个值
unshift();
反转显示不改变原来数组
reverse();
数组合并
concat;
截取数组(不改变原来的数组)
slice(start,end);
只能针对数组第一个字符排序改变原来数组
sort(show);('asc|desc' )升序降序排序
show(a,b){
return a-b;
}
截取数组(改变原来的数组)
splice(start,length);
字符串大小写转换
toUpperCase();
toLowerCase();
正则表达式
18. js对象
js内置对象
js事件对象
BOM浏览器对象
DOM文档对象