javascript - 怎么让js只弹出一次
本文介绍了javascript - 怎么让js只弹出一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
//选择内容
$(".joy-alert-list li").click(function(){
if($(this).hasClass('current')){
$(this).removeClass('current');
}else{
$(this).addClass('current');
};
//点击确定按钮
$(".joy-btn").click(function(){
var currList = $('.current').length;
alert(currList);
});
});
点击确定按钮,弹出次数一直在增加。第一次选择,弹出一次,然后再选择,点击确定会弹出2次。
解决方案
$('.joy-alert-list li').click(function(){
$(this).toggleClass('current');
});
$('.joy-btn').click(function(){
alert($('.current').length);
});
这篇关于javascript - 怎么让js只弹出一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文