1.加载新文档
<html>
<head>
<script>
function newDoc()
{
window.location.assign("http://www.w3cschool.cc")
}
</script>
</head>
<body>
<input type="button" value="Load new document" onclick="newDoc()">
</body>
</html>
2.确认框&提示框
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="p1"></p>
<button type="button" onclick="my()">我是确认框</button>
<p id="p2"></p>
<button type="button" onclick="my2()">我是</button>
<script>
//确认框
function my(){
var r=confirm("加油吧!");
var x="";
if(r==1){
x="点击了确认";
}else{
x="点击了取消";
}
document.getElementById("p1").innerHTML=x;
}
//提示框
function my2(){
var per=prompt("请输入你的名字","江芳芳");
if(per!=""&&per!=null){
x="你好!"+per+"今天感觉怎么样呀";
}
document.getElementById("p2").innerHTML=x;
}
</script>
</body>
</html>
3.计时事件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<p id="p1">这是段落1</p>
<button type="button" onclick="jishi()">点我点我</button>
<button type="button" onclick="stop()">点我停止</button>
<script>
function my(){
alert("hello\n江芳芳!");
}
function jishi(){
x=setInterval(my,3000);
}
function stop(){
clearInterval(x);
}
</script>
</body>
</html>