$()的第二个参数是什么意思? [英] What does the second argument to $() mean?
问题描述
var favorites = $(#favorites);
var favoritesFooter = $(#favoritesFooter,收藏夹);
我不知道在第二个语句中逗号是什么意思 $( #favoritesFooter,收藏夹);
同样在上述情况下,以下语句将执行或表示什么;
favoritesFooter.prev()。after(newHTML);
第二条语句是 favoritesFooter
内的jQuery对象收藏夹
。
As你正在处理应该是唯一的ID,这是毫无意义的 - $(#favoritesFooter)
是最佳做法。
关于 favoritesFooter.prev()
它也没有意义,假设ID是唯一的,所以你只有一个元素的集合,因此 prev()
将返回空的jQuery集合。
.prev()
将采用以前的DOM元素 - 在您的情况下,它会在 favoritesFooter
元素之前推入 newHTML
。
I have a jQuery code as follows;
var favorites = $("#favorites");
var favoritesFooter = $("#favoritesFooter",favorites);
I am not sure what does the comma mean in the 2nd statement $("#favoritesFooter",favorites);
Also what would the following statement do or represent in the above case;
favoritesFooter.prev().after(newHTML);
The second statement means "search for element with ID of favoritesFooter
inside the jQuery object favorites
".
As you're dealing with ID which should be unique, it's pointless - $("#favoritesFooter")
is the best practice.
Regarding favoritesFooter.prev()
it's also pointless, assuming the ID is unique so you have collection with only one element thus prev()
will return empty jQuery collection.
The .prev()
will take the previous DOM element - in your case, it will push newHTML
right before the favoritesFooter
element.
这篇关于$()的第二个参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!