我有很多 div
,比如说 .class
类。我需要根据特定路线为它们分配宽度
$(".class").width($(this).parent().next().find("code").width())
但是,由于某种原因,它不适用于 $(this)
但当我这样做时它可以:
$(".class").width($(".class").parent().next().find("code").width())
但显然只适用于第一个。有什么线索吗?
最佳答案
jQuery width()方法接受一个函数:
A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set.
$(".class").width(function () {
return $(this).parent().next().find("code").width()
});
关于javascript - $ (".class").width($(this)...) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27235348/