我不明白当你做一个像这样的.show()链时会发生什么.我也没有写这段代码或者想知道如何弄清楚这里发生了什么.因此这个问题.
// Remove favorite category
$(".FavoriteRemove").click(function() {
var cat = $(this).parents(".Category"); //the parent of the clicked item is the category/bundle
var catid = $(this).attr("catid"); //the id tag on the clicked item is the BundleID
$.post($(this).attr("href"), function() { //the href tag is the post URL for adding a favorite
cat.remove(); //here we remove the category/bundle
//*** WHAT IS THIS DOING? v
$(".Category[catid=" + catid + "]").show().parent().show();
//*** NO THAT UP THERE ^
if ($(".FavoriteCategories div").length == 0)
$(".FavoriteCategories").hide();
//bindCategories();
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
有人可以描述这意味着什么吗?我知道目标是类'Category',其属性与ID匹配,但我不明白函数链的含义.
谢谢.
show()(文档) 具有 class 的元素Category,以及catid具有给定变量值的属性。parent()然后使用(docs)方法向上遍历到其父级。show()(文档) 父级。“显示”意味着将其display样式属性设置为其none初始(或默认)值,例如block.