码迷,mamicode.com
首页 > Web开发 > 详细

js_外部对象——发送消息例子

时间:2017-10-07 14:26:10      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:onclick   timeout   on()   fun   func   显示   type   htm   asc   

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>邮件发送</title>
<script type="text/javascript">
var id;
var p;
//发送
function send() {
//若id非空则定时器已启动过,那么就不要再启动了
if(id){
return;
}
//显示正在发送
p=document.getElementById("msg");
p.innerHTML="正在发送";
//推迟3秒显示已发送
id=setTimeout(function(){
p.innerHTML="已发送";
id=null;
}, 3000)
}
//撤销
function cancel() {
//id非空时,表示定时器已启动才可以撤销
if(id){
//显示为已撤销
p=document.getElementById("msg");
p.innerHTML="已撤销"
clearTimeout(id);
//为了下次可以启动,要清空id;
id=null;
}
}
</script>
</head>
<body>
<p>
<input type="button" value="发送"
onclick="send();">
<input type="button" value="撤销"
onclick="cancel();">
</p>
<p id="msg"></p>
</body>
</html>

js_外部对象——发送消息例子

标签:onclick   timeout   on()   fun   func   显示   type   htm   asc   

原文地址:http://www.cnblogs.com/Bighua123/p/7634324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!