我有一个类agg-drop的列表,其项目有一个类名sortedli。这些项目有2个切换状态。我使用.clone(true)克隆这些项目,该项目将该项目添加到类名为“all-drop”的列表中。此列表中的项目有3个切换状态。现在,如果我要切换新克隆列表中的项目,则前两次单击不会执行任何操作,大概是因为它正在按顺序切换函数,并且切换依赖于类名称。无论如何要防止这一点?jquery切换 - 防止顺序切换
$(".sortedli").toggle(function(){
if($(this).parent().hasClass('agg-drop')){
$(this).css("background","orange");
}},
function(){
if($(this).parent().hasClass('agg-drop')){
$(this).css("background","yellow");
}},
function(){
if($(this).parent().hasClass('all-drop')){
$(this).css("background","red");
}},
function(){
if($(this).parent().hasClass('all-drop')){
$(this).css("background","green");
}},
function(){
if($(this).parent().hasClass('all-drop')){
$(this).css("background","blue");
}}
);
你能对这个问题 –