3
이 질문은 약간의 두 가지 구문입니다. 먼저, 제목 질문. 다음은 내가 가지고있는 것입니다 :"this"를 jQuery의 "each"에 대한 부모 스택에 추가
// Report all of the parents
$(this).parents().each(function(i){
// Collect the parts in a var
var $crumb = '';
// Get the tag name of the parent
$crumb += "<span class='tagName'>"+this.tagName+"</span>";
// And finally, report it
$breadcrumbs.prepend($crumb);
});
불행히도, 이것은 실제 요소 자체를 포함하지 않으며 부모 만 포함합니다. "이 부모님"같은 말을 할 수있는 방법이 있습니까?
이제 두 번째 질문입니다. 스택에 추가 할 수 없다면 어떻게이 기능을 유지하면서 해당 기능의 내장을 다른 기능으로 분리 할 수 있습니까? 그것은 다음과 같을까요?
// Function to report the findings
function crumble(e){
// Collect the parts in a var
var $crumb = '';
// Get the tag name of the parent
$crumb += "<span class='tagName'>"+this.tagName+"</span>";
// And finally, report it
$breadcrumbs.prepend($crumb);
};
$(this).parents().each(crumble());
미리 감사드립니다.
니스! 감사. 함수를 호출하거나 호출하지 않는 것에 대한 참조를 추천 해 주시겠습니까? 나는 더 많은 것을 배우고 싶습니다 =) – Matrym
오, 여기 당신의 솔루션에 대한 재미있는 작은 사실이 있습니다. 그것은 스택의 순서를 바꿉니다! reverse()로 해결하거나 append (앞에 붙이는 대신)하기에 충분히 쉽다. – Matrym