先看body中的内容:
<body onload="demo1()">
<p>
<input type="button" id="" value="window.alert" onclick="demo1()"/>
</p>
<p>
<input type="button" id="" value="window.confirm" onclick="demo2()"/>
</p>
<p>
<input type="button" id="" value="window.prompt" onclick="demo3()"/>
</p>
当前时间是:<span id="time"></span>
<p>
<input type="button" id="" value="停止时间" onclick="demo4()" />
</p>
<p>
<input type="button" id="" value="去百度" onclick="demo5()" />
</p>
<p>
<input type="button" id="" value="离开此页" onclick="demo6()" />
</p>
</body>
三种弹框的方式:
1.只有一个确定按钮的弹框:
function demo1(){
window.alert("只有一个确定按钮");
}
2.有确定和取消按钮:
function demo2(){
//确定为true 取消为false
var c=window.confirm("你确定要退出吗?");
window.alert(c);
}
注意:俩个按钮都有返回值:确定为true,取消为false
3.含有输入框的弹框:
function demo3(){
var p=window.prompt("请输入你的账号!!");
window.alert(p);
}
注意:返回值是个string
定时器的应用:
function gettime(){
var date=new Date();
var t=date.toLocaleString();
var id=document.getElementById("time");
id.innerHTML=t;
}
var si=window.setInterval("gettime()",1000);
function demo4(){
window.clearInterval(si);
}
window.clearInterval(si);停止时间。
另起一页打开页面:
function demo5(){
window.open("http://www.baidu.com");
}
退出此页面:
function demo6(){
var c=window.confirm("你确定要退出吗?");
if(c==true){
window.close();
}