<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JavaScript中的Window</title>
<!--Window学习
1.Window常用的方法
对话框
alert---弹出警告框(弹出的窗口只能点确定)
confirm----确认框(弹出的窗口既可以点确定,也可以点取消),点确定会返回true,点取消会返回false
prompt---prompt("描述内容"):弹出一个输入框,并可以获取输入结果
延时函数
setTimeout("执行动作",毫秒数)----延误指定的毫秒数,然后执行指定的动作,执行动作可以是另外的方法,也可以是匿名的方法,注意必须加引号
clearTimeOut---清除指定的延时函数
setInterval("执行动作",毫秒数)---每隔多少秒都会执行一次这个函数
子窗口
window.open("open.html","win","width=100,heigth=200")
2.location
3.history
-->
<script type="text/javascript">
var ids;
function testAlert(){
alert("测试alert");
}
function testConfirm(){
var testC=confirm("测试confirm");
alert(testC);//点确定会返回true,点取消会返回false,
}
function testPrompt(){
var tetsp=prompt("请输入一个值");
alert(tetsp);
}
function testTimeout1(){
setTimeout("alert('直接使用alert')",2000);
}
function testTimeout(){
setTimeout("testTimeoutFunction()",3000);//调用另外的方法
}
function testTimeoutFunction(){
alert("掉用方法");
}
function testTimeout2(){
ids=setTimeout(function(){
alert("匿名方法");
},1000);
}
function testClearTimeOut(){
clearTimeout(ids);
}
function testSetInterval(){
setInterval(function(){
alert("延时函数");
},1000);
}
function testWindow(){
window.open("son.html","win","width=20,heigth=10,top=100,left=100");
}
</script>
</head>
<body>
<input type="button" value="测试alert" onclick="testAlert()" />
<input type="button" value="测试confirm" onclick="testConfirm()" />
<input type="button" value="测试prompt" onclick="testPrompt()" />
<hr />
<input type="button" value="测试setTimeout1" onclick="testTimeout1()" />
<input type="button" value="测试setTimeout" onclick="testTimeout()" />
<input type="button" value="测试setTimeout2" onclick="testTimeout2()" />
<hr />
<input type="button" value="测试ClearTimeOut" onclick="testClearTimeOut()" />
<hr />
<input type="button" value="测试setInterval" onclick="testSetInterval()" />
<hr />
<input type="button" value="测试子窗口" onclick="testWindow()" />
</body>
</html>
JavaScript中的Window
最新推荐文章于 2024-08-22 23:42:23 发布