<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
window.onload = function () {
//1.confirm演示
document.getElementById('btn1').onclick = function () {
if (confirm('确定会出现小妖怪')) {
alert('我是小妖怪');
}
else {
alert('你没有点确定哦');
}
};
//2.location演示
this.document.getElementById('btnGoGoogle').onclick = function () {
window.location.href = "http://www.baidu.com";
};
//3.setInterval与clearInterval
var intervalID;//声明一个变量接收计时器id
//开始计时器按钮
this.document.getElementById('btnStart').onclick = function () {
intervalID = setInterval(function () {
//禁用开始按钮,防止多次触发
document.getElementById('btnStart').disabled = true;
//循环增加数值
var n = document.getElementById('txtTest').value;//获取当前txt数值
n = ++n;
document.getElementById('txtTest').value= n;
}, 1000);//(code,ms)代码,毫秒;返回值是intervalid
//停止计时器按钮
};
this.document.getElementById('btnStop').onclick = function () {
window.clearInterval(intervalID);
document.getElementById('btnStart').disabled = false;
};
};//onload
</script>
</head>
<body>
1.window的confirm方法
<p><input type="button" name="btn1" value="测试一下confirm" id="btn1"/></p>
<p>2.window.location.href=‘’ //链接到某个网址</p>
<p><input type="button" name="btnLocation" value="去baidu看看" id="btnGoGoogle" /></p>
<p>3.window.setInterval(code,delay)//计时器控件,第一个参数代码,第二个时间间隔(毫秒),返回值是一个intervalID(计时器id),用于停止计时器</p>
<p><input type="text" name="txtTest" value=""id="txtTest" /></p>
<p><input type="button" name="btnStart" value="开始" id="btnStart" />
<input type="button" name="btnStop" value="停止" id="btnStop" />
</p>
</body>
</html>
JS-window对象的若干方法一:confirm,location以及计时器
最新推荐文章于 2024-01-11 11:18:06 发布