1:每隔一秒刷新一次页面
document.write(Date());
function Refresh() {
window.location.reload();
}
setTimeout('Refresh()',1000);
2:
onlaod 和 onunload 事件会在用户进入或离开界面的时候被触发。
3:
onchange 事件常结合对输入字段的验证来使用。
4:
onmouseover 鼠标移到元素上方时触发函数;
onmouseout 鼠标移出元素上方的时候触发函数。
类似:onmousedown、onmouseup,onclick
5:
DOM元素 节点:
向HTML添加元素需创建该元素,然后向一个已存在的元素追加该元素;
creatElement(): 创建元素节点
document.createTextNode(): 创建文本节点;
appendChild(): 向节点添加最后一个子节点;
6:
删除已有的HTML元素:
需要先获得该元素的父元素:var parent=document.getElementById("div1");
找到div1中的子元素:var child=document.getElementById("p1");
从父元素中删除子元素:parent.removeChild(child);
来源:http://www.w3school.com.cn/js/js_htmldom_elements.asp
7:
toUpperCase(): 将文本转化为大写。
8:
对象构造器
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
}
Bill = new preson("Bill", "Gate", 30);
document.write(Bill.firstname + " is " + Bill.age + " years old.");
9:
Number对象
数字属性和方法
属性:
MAX VALUE
MIN VALUE
NEGATIVE INFINITIVE
POSITIVE INFINITIVE
NaN
prototype
constructor
方法:
toExponential()
toFixed()
toPrecision()
toString()
valueOf()
10:
字符串:
indexOf() :定位字符串中某一个指定的字符首次出现的位置。
var str="Hello world!"document.write(str.indexOf("Hello") )
match(): 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。
replace() :在字符串中用某些字符替换另一些字符。
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))
11:
Date(): 返回当日日期:document.write(Date())
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
显示一个钟表:
12:
数组:
合并两个数组: concat() : arr1.concat(arr2)
join() : 将数组的所有元素组成一个字符串。
sort() : 对数组排序: 对文字:arr.sort() 对数组:arr.sort(sortNumber))
13:
逻辑对象 Boolean
14:
算数对象:Math.round(0.6) = 1; Math.round(0.49) = 0; Math.round(-4.40) = -4;
Math.random() : 返回0~1之间的随机数
Math.max(5,7);
Math.min(1,2);
算数值
JavaScript 提供 8 种可被 Math 对象访问的算数值:
常数
圆周率
2 的平方根
1/2 的平方根
2 的自然对数
10 的自然对数
以 2 为底的 e 的对数
以 10 为底的 e 的对数
这是在 Javascript 中使用这些值的方法:(与上面的算数值一一对应)
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
Math.floor(x) : 返回小于等于x且与x最接近的整数
15 :
正则表达式 RegExp
RegExp 对象有 3 个方法:test()、exec() 以及 compile()。
test() 方法检索字符串中的指定值。返回值是 true 或 false。
exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配,则返回 null。
16:
JavaScript window:
浏览器窗口内部高度:window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
浏览器窗口内部宽度:window.innerWidth || document.documentElement.clientWidth || document.documentElement.clientWidth
其他window方法:
window.open() - 打开新窗口
window.close() - 关闭当前窗口
window.moveTo() - 移动当前窗口
window.resizeTo() - 调整当前窗口的尺寸
17:
JavaScript window Screen
可用屏幕宽度:screen.availWidth
可用屏幕高度:screen.availHeight
18:
JavaScript window Location:
window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面。window.location对象在编写时可不使用 window 这个前缀。
location.hostname 返回 web 主机的域名
location.pathname 返回当前页面的路径和文件名
location.port 返回 web 主机的端口 (80 或 443)
location.protocol 返回所使用的 web 协议(http:// 或 https://)
Window Location Href : location.href 属性返回当前页面的 URL。
加载一个新文档:window.location.assign("new url")
19 :
window.history.back()
window.history.forward()
20 :
window.navigator :包含有关访问者浏览器的信息
21 :
消息框:
警告框;
确认框: var r = confirm("text")
提示框 : var r = prompt("文本", "默认值")
22:
网友评论