.一个浏览器窗口中的DOM顺序是:
window->(navigator,screen,history,location,document)
window.location属性
protocol(http:),
hostname(www.example.com),
port(80),
host(www.example.com:80),
pathname("/a/a.html"),
hash("#giantGizmo",指跳转到相应的锚记),
href(全部的信息)
window.location.href = 'url'//本地链接ur地址
窗口
window.open() //打开一个窗口
window.opener()//打开当前窗口的父窗口
window.close() //关闭一个窗口
window.self //窗口本身
window.scroll(x,y)
window.scrollby//获取窗口滚动位置
function fullScreen(){ this.moveTo(0,0);
this.outerWidth=screen.availWidth;
this.outerHeight=screen.availHeight;
}
window.maximize=fullScreen; //窗口全屏
function verifyClose () {
event.returnValue = 'we really like and hold
you will stay longer'
}
window.onbeforeunload() = verifyClose;
//页面刷新或关闭之前提示,可阻止
4种刷新
window.location.reload()刷新当前页面.
parent.location.reload()刷新父亲对象(用于框架)
opener.location.reload()刷新父窗口对象(用于单开窗口)
top.location.reload()刷新最顶端对象(用于多开窗口)
历史相关操作
window.history.back()返回上一页,
window.history.forward()返回下一页,
window.history.go(返回第几页,也可以使用访问过的URL)//-1返回上一页
三种弹出框
window.alert()//提示框
window.confirm()//确认框
window.prompt()//输入提示框
数字转字符
(number + '')
字符转数字
string.parseInt() // 转整数
string.parseFloat() // 转浮点数
文档相关操作
document.forms[0]//多个表单表示
document.forms[1].selectName.options[selectedIndex].value
window.
document.createElement()//创建文档元素
document.onload()
document.onunload()//不能阻止页面刷新或关闭
判断相关属性
checked //判断是否选中,返回布尔值
contentEditable//可设置元素是否可被修改,
isContentEditable//返回是否可修改的状态.
disabled//设置禁止状态
isDisabled//判断是否为禁止状态
isNaN//判断是否为数值型
字符串相关操作
string1.indexOf('string2')//返回2在1中首次出现的位置 -1为未找到
string.lastIndexOf()
string.match()
string.replace()
string.spilt()
string.charAt(number)//获取指定位置的字符(1个)
string.substring(firstNumber,lastNumber)
//取出字符串中指定起点和终点的子字符串
string.toUpperCase() //小写转大写
string.toLowerCase() //大写转小写
string.concat()//字符串拼接,与+=作用类似
string += addString //字符串追加连接符
数字函数
Math.PI()//圆周率
Math.random()//0~1随机数
Math.SQRT2(4)//4的开平方
Math.pow(2,10)//2的10次方
Math.floor()
Math.max(value1,value2)
Math.min(value1,value2)
Math.round()//四舍五入
Math.floor(Math.random() * (n + 1))//1~n随机整数
日期函数
dateObj.getTime()得到时间,
dateObj.getYear()得到年份,
dateObj.getFullYear()得到四位的年份,
dateObj.getMonth()得到月份,
dateObj.getDate()得到日,
dateObj.getDay()得到日期几,
dateObj.getHours()得到小时,
dateObj.getMinutes()得到分,
dateObj.getSeconds()得到秒,
dateObj.setTime(value)设置时间,
dateObj.setYear(val)设置年,
dateObj.setMonth(val)设置月,
dateObj.setDate(val)设置日,
dateObj.setDay(val)设置星期几,
dateObj.setHours设置小时,
dateObj.setMinutes(val)设置分,
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]
JS内建对象
String,Boolean,Number,Array,Function
Date,Math,Object,RegExp,Error,
EvalError,RangeError,ReferenceError,
SyntaxError,TypeError,URIError
防止用户对文本框中输入文本:
onfocus="this.blur()"
方法
document.all.tags('div').length //取出div元素在页面中出现的数量
延迟
setInterval(function,time)
setTimeout(function,time)