

限时限次数点击按钮
source link: https://www.fly63.com/article/detial/11295
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

扫一扫分享
- 用一个变量作为计数,点击一次,计数加一
- 点击函数内判断计数变量
- 设置定时恢复
<body>
<div class="a123">
<a class="btn bg1" onclick="doIt()">123123</a>
<br>
<div class="show"></div>
</div>
</body>
css代码
.btn{
display: inline-block;
width: 80px;
height: 40px;
line-height: 40px;
border-radius: 5px;
cursor: pointer;
}
.bg1{
background-color: rgb(21, 93, 248);
color: white;
}
.bg2{
background-color: rgb(53, 53, 53);
color: white;
}
.a123{
width: 500px;
height: 300px;
border: 1px solid pink;
margin: 200px auto;
padding: 30px;
text-align: center;
}
JS代码
<script>
//计数变量
var count = 0;
//3秒钟重置一次计数 并恢复按钮
var resetC = window.setInterval(function(){
//恢复计数 恢复点击事件
count = 0;
$('.btn').attr('onclick','doIt()');
//恢复背景颜色
$('.btn').addClass('bg1');
$('.btn').removeClass('bg2');
},1000*10);
//点击事件
function doIt(){
//点一次 计数加一
count += 1;
//判断计数 大于2 就
if(count >= 2){
//移除 点击函数
$('.btn').removeAttr('onclick');
//更换背景CSS
$('.btn').addClass('bg2');
$('.btn').removeClass('bg1');
}
//将计数显示出来
$('.show').text(count);
}
</script>
1.定时一次setTimeout(),单次使用
var timeOut = window.setTimeout(function(){
//里面放定时任务
},1000);
//1000 是指时间,即1000ms
2.循环定时setInterval(),需要使用clearInterval()来清除定时任务
var resetC = window.setInterval(function(){
//里面放定时任务
},1000);
/*
1000 是指时间,即1000ms
这个定时任务,每隔1s就会触发一次。
如果要清除,使用clearInterval()函数
*/
window.clearInterval(resetC);
禁止选中文字
使用<a>标签作为点击元素, 当点击事件频繁时 ,文字会被选中,不好看
CSS代码实现
body{
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;
}
来自:https://www.cnblogs.com/jokrhell/archive/2022/03/25/16053482.html
Recommend
-
188
-
15
需具备的条件 若要顺利阅读本篇文章, 需要你具备如下条件: 本篇文章的环境: 环境版本Windows10Android Studio3.5Flutter1.19.0-2.0.pre一定要注意环境的差异, 考虑不兼容的可能性; 并且具备以上条件. 否则阅读本篇...
-
6
从减少点击次数,到降低使用负荷 昨天B.B.King病逝,享年89岁。几乎循环了一晚上The Thrill Is Gone.这种事从情感上讲有点不...
-
8
js如何判断哪个按钮被点击了?发布于 2015-09-16 页面上有两个按钮,点击后都调用同样的js函数,只是传入的参数不同,请问如何在这个函数中判断是点...
-
7
1. 多按钮被点击
-
8
外贸出口退税的时限规定与必备材料 发布者:货之家 来源:http://www.51w2c.com 发布日期:2021-09-14 浏览:18次 摘要:根据现行税制规定,我国出口货物退(免)税的税种是流转税(又称间接税)范围内的增值税、消费税两个税种...
-
6
如何改变所有按钮的点击行为? 欧雷 发表于 1 天之前 0 条评论 被人问了这样一个问题—— 现在有这样...
-
7
支持无时限8K视频内录!佳能公布全新专业级微单EOS R5c|相机_网易数码
-
8
在 Web 中,大部分按钮可能都是平平无奇的,有时候为了强调品牌特殊或者满足特殊功能,可能需要给按钮添加一点点击动效。比如,用过
-
9
时限三天爱上我剧情简介 2022年上映,由林森执导,郑艺彬,谭盐盐,纪一曈,安钦夫等主演的《时限三天爱上我》在中国大陆上映。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK