我试图找到一种简单的方法来将点击事件附加到一个元素,这对于第一次和第二次点击事件来说是相当容易的。但是,我试图完成的是三次点击切换。如何为第三次点击分配jQuery点击事件?
1st click = addClas('one'); 2nd click = removeClass('one')。addClass('two'); 3rd click = removeClass('two')。addClass('three'); 下次点击会==第一次点击并再次通过循环..
我使用一个简单的div和通过CSS应用样式,更改元素背景位置 - 所有非常典型和容易..并且是蛋糕做一个切换()或点击()事件..但我无法弄清楚我的生活如何处理第三次点击! :d
这里是我的标记,例如用途:
任何帮助是极大的赞赏!
UPDATE: 我有一些作品..但,恕我直言,它的丑陋和杂乱..还有得是一个更清洁,这样做的更简洁的方式: $(“ tri_switch”)。点击(函数(){VAR this_id = $(本).attr( “ID”);
if($(this).hasClass("one")){
$("input#user_"+this_id).attr('checked','checked');
$("input.tri_switch_radio").not("#user_"+this_id).removeAttr('checked');
$(this).removeClass('one').addClass('two');
$("span.tri_switch_checked").text('User');
}
else if ($(this).hasClass("two")){
$("input#admin_"+this_id).attr('checked','checked');
$("input.tri_switch_radio").not("#admin_"+this_id).removeAttr('checked');
$(this).removeClass('two').addClass('three');
$("span.tri_switch_checked").text('Admin');
}
else if ($(this).hasClass("three")){
$("input#readonly_"+this_id).attr('checked','checked');
$("input.tri_switch_radio").not("#readonly_"+this_id).removeAttr('checked');
$(this).removeClass('three').addClass('one');
$("span.tri_switch_checked").text('Readonly');
}
//警报(this_id); });
我甚至想过增加一个计数值,并在第三次点击LOL时重新设置它。只要它的'干净的编码',我对任何使这项工作开放的东西都是开放的:D – revive 2010-08-12 09:31:52