一、变量(算术运算符,逻辑运算符等)
二、数组(二维数组)
var myarr=new Array();
三、控制语句
四、函数
function add2(x,y){
sum=x+y;
return sum;
}
五、事件响应,让网页交互
六、内置对象
Date对象
String字符串对象
- stringObject.charAt(index)返回指定位置的字符
- stringObject.indexOf(substring, startpos)返回某个指定的字符串值在字符串中首次出现的位置
- stringObject.split(separator,limit)
- split() 方法将字符串分割为字符串数组,并返回此数组。
- stringObject.substring(starPos,stopPos)
- 提取字符串中介于两个指定下标之间的字符。
- stringObject.substr(startPos,length)
- 提取从 startPos位置开始的指定数目的字符串
Math对象
- 向上取整ceil();
- 向下取整floor();
- 四舍五入round();
- 随机数random();返回介于 0 ~ 1(大于或等于 0 但小于 1)之间的一个随机数。
- document.write((Math.random())*10);
- 获得0 ~ 10之间的随机数
Array数组对象
七、浏览器对象
window对象(主要看计时器)
History对象
Location对象
Navigator对象(包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本。)
screen对象
(screen对象用于获取用户的屏幕信息。)
八、互动方法
- 输出document.write();
- 警告alert();
- 确认confirm();用户点确定或者取消
- 提问prompt();需要用户输入文字
- 打开窗口window.open();
- 关闭窗口window.close();
九、Dom对象,控制HTML元素
elementNode.getAttribute(name)通过元素节点的属性名称获取属性的值
elementNode.setAttribute(name,value)增加一个指定名称和值的新属性,或者把一个现有的属性设定为指定的值。
elementNode.childNodes访问选定元素节点下的所有子节点的列表,返回的值可以看作是一个数组,他具有length属性
node.firstChild,node.lastChild
elementNode.parentNode获取指点节点的父节点
nodeObject.nextSibling,nodeObject.previousSibling
appendChild(newnode),insertBefore(newnode,node);
nodeObject.removeChild(node),
node.replaceChild (newnode,oldnew )
document.createElement(tagName)
document.createTextNode(data)
获取文本obj.innerHTML
改变样式obj.style.color
隐藏显示obj.style.display=none/block;