我的代码似乎有缺陷,我在里面设置了两个具有相同代码的函数。我可以将它们合二为一吗?
// remove sets
$('body').on("click", "span.remove", function() {
var self = $(this),
total = self.parents('ul').children('li').size(); // grab total number of li's
// remove (set) li if total greater than 1, else remove exercise
if(total > 1)
self.parent('li').fadeOut('slow', function() {
// remove clicked .li and reset list order
$(this).remove();
reset();
});
else
self.parents('section').fadeTo('slow', 0.33).slideUp('slow', function() {
// remove clicked .li and reset list order
$(this).remove();
reset();
});
});
是否可以执行以下操作:
if(total > 1)
var f = self.parent('li').fadeOut('slow', function()
else
var f = self.parents('section').fadeTo('slow', 0.33).slideUp('slow', function()
f {
// remove clicked .li and rest list order
$(this).remove();
reset();
});