1
這會給出空輸出,因爲console.log從不會被調用。我如何強制jQuery找到所有元素,甚至是頂級元素?jQuery - 查找包含自我
$("<div attr></div><div></div>")
.andSelf()
.find('[attr]')
.each(function (index, el) {console.log(el);});
這會給出空輸出,因爲console.log從不會被調用。我如何強制jQuery找到所有元素,甚至是頂級元素?jQuery - 查找包含自我
$("<div attr></div><div></div>")
.andSelf()
.find('[attr]')
.each(function (index, el) {console.log(el);});
您可以使用發現使用.find('[attr]')
然後重新添加匹配使用.addBack('[attr]')
$("<div attr></div><div></div>")
.find('[attr]')
.addBack('[attr]')
.each(function (index, el) {
console.log(el);
});
演示過濾器的根元素,以找到與所述性質的後代元素:Fiddle
TY,卻發現必須不返回,我不明白爲什麼這個發現必須在那裏 – Krab
好吧,我現在明白了 – Krab