有没有办法将最后两行代码格式组合成一个?
str = "1, 2, 3, 4, 5, "
str = str:gsub("%p", {[","] = " >" }) -- replaces ',' with '>'
str = string.sub(str, 1, #str - 2) --removes last whitespace + comma
提前致谢:)
答案 0 :(得分:3)
$(".tile a").click(function () {
$(this).closest("div").toggleClass("selected_tile");
//use varible!! no need to see (this).parent.parent.parent so many times XD
var grandParent = $(this).parent().parent();
//Check if it already has an "old class"
if ((grandParent.attr("data-old-class"))&&grandParent.attr("data-old-class") !== '') {
grandParent.removeClass("col-md-12").addClass(grandParent.attr("data-old-class"));
//remove the old class (its more generic than toggle)
grandParent.attr("data-old-class","");
} else {
grandParent.attr("data-old-class", grandParent.attr("class"));
grandParent.attr("class","");
grandParent.addClass("col-md-12");
}
});
这将做你想做的事。
但是,Egor的优雅更为优雅:str = "1, 2, 3, 4, 5, "
str = str:sub(1, #str-2):gsub("%p", {[","] = " >" })