onload事件
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script>
var str = "欢迎来到我的空间";
function Move(){
//alert(str.substr(1));
//如何截取第一个字符
//alert(str.charAt(0));
str = str.substr(1)+str.charAt(0);
window.status = str;
document.title = str;
setTimeout("Move()",500);
}
//setInterval("Move()",500);
</script>
</head>
<body οnlοad="Move()">
</body>
</html>
获得焦点事件
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
用户名:<input type="text" id="username" value="请输入用户名" οnfοcus="clearInput()" οnblur="getInput()"/>
密码: <input type="password" id="password"/>
</body>
<script>
function clearInput(){
//获得输入框的值
var username = document.getElementById("username");
username.value = '';
}
function getInput(){
//获得输入框的值
var username = document.getElementById("username");
username.value = '请输入用户名';
}
</script>
</html>
内容改变事件
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<select id="select" οnchange="changeCont()">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<div id="div1">改变文字的大小</div>
</body>
<script>
function changeCont(){
//先获得下拉列表的值
var num = document.getElementById("select");
var optValue = num.value;
var divCont = document.getElementById("div1");
divCont.style.fontSize = (optValue*10)+'px';
}
</script>
</html>