function toast(text, time) {
let toast = document.getElementById('toast');
let toast_box = document.getElementsByClassName('toast_box')[0];
toast.innerHTML = text;
toast_box.style.animation = 'show 1.5s';
toast_box.style.display = 'inline-block';
setTimeout(function(){
toast_box.style.animation = 'hide 1.5s';
setTimeout(function(){
toast_box.style.display = 'none';
}, 1000)
}, time)
}
function fn(callback){
fn.prototype.init(callback);
}
fn.prototype = {
canclick: true,
init: function(callback){
if(this.canclick){
this.canclick = false
callback();
setTimeout(function(){
this.canclick = true
}.bind(this),2500)
}else{
console.log('1s中之内不允许重复点击');
}
}
}
$(".a").click(function(){
console.log("a");
fn(function(){
toast("异常提醒", 1400);
});
})
这里用jquery中的$(".类名")来进行特定元素的绑定