这个jQuery语法在做什么?
我不理解.width和.parent()的。这个jQuery语法在做什么?,jquery,Jquery,我不理解.width和.parent()的。 谢谢。它将图像的宽度设置为其父对象的父对象的宽度(以及其他CSS设置)。请参阅和。您是否阅读了jQuery网站上关于这些方法的文档? $(".topLevelCategoryContainer img").width($(this).parent().parent().width()).css({ "text-align": "center", "border": "none", "margin-left": "0" }); // this get
谢谢。它将图像的宽度设置为其父对象的父对象的宽度(以及其他CSS设置)。请参阅和。您是否阅读了jQuery网站上关于这些方法的文档?
$(".topLevelCategoryContainer img").width($(this).parent().parent().width()).css({ "text-align": "center", "border": "none", "margin-left": "0" });
// this gets images within the .topLevelCategoryContainer element
$(".topLevelCategoryContainer img")
// this sets the width of the image
.width(
// this gets the value to set the width to, in this case
// to the same width as the images parents parent
$(this).parent().parent().width()
)
//this sets CSS on the image
.css({
"text-align": "center",
"border": "none",
"margin-left": "0"
});