1.JS的对象操作
对象的基本特性具有属性和方法。
对象理解上可以理解成一个种类事物的一个。
2.对象种类
字符串对象String,时间对象 Date,数学对象 Math,数组对象等。
3.浏览器window对象
例如window.alert(“hello”);是指输出。
Confirm向用户确认,setIntval设置时间,clearInval定时器对象,setTimeout设置超时时间等。
Navigator浏览器信息对象。
Location地址栏信息对象。
History 历史信息对象。
<input type=”button” value=”button” οnclick=”javascript:window.history.back();(或者forward();)”>跳转页面到后一个或者前一个。
Screen屏幕对象。
上面的分类中还有子分类,参考文档下载地址见最后。
4.var的重要性
函数(function)首先在内部查找变量,当查找不到时会向外查找,直到浏览器找不到,才会报错。
在上面情况的基础上,不加var就会出现作用域问题,污染全局变量。
5.DOM操作
document.getElementById(‘标签id’)用于对标签进行操作。
6.示例代码
<!DOCTYPE html>
<html>
<head>
<title>特效</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div
{
width: 200px;
height: 200px;
}
#before
{
background-color: red;
}
#after
{
background-color: blue;
}
</style>
<script>
function changeColor()
{
var div = document.getElementById('before');
div.id = 'after';
}
</script>
</head>
<body>
<h1>特效</h1>
<div id="before" οnclick="changeColor();"></div>
</body>
</html>
Javascript参考手册下载地址:
http://download.csdn.net/detail/u011822862/8947815