这个问题有点像两个问题.首先是标题问题.这是我得到的:
// 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); });
不幸的是,这不包括实际元素本身,只包括父母.有什么方法可以说“这和父母”吗?
现在,第二个问题.如果我无法添加到堆栈中,我如何将该函数的内容分成另一个函数,同时保留它的“this”能力?会是这样的:
// 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());
在此先感谢您的时间!
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。