此 jQuery 代码中的最后一行不起作用
我已经设置了这段代码,由于某种原因,除了最后一行之外,一切正常。
function getBlogs(element, url, limit, feed){
jQuery(element).load(url+ ' .blog_list .module_body:lt('+ limit+ ')', function(){
jQuery(this).prepend("<a class='home-rss' href='"+ feed+ "'></a>");
jQuery(this).append("<a class='view-all-blogs' href='"+ url+"'>View More »</a>");
// ** The following line isn't working: **
jQuery(".tab-container .module_body .postbody").last("a").addClass("continue-link");
});
}
var blogUrl = 'http://mysite.com/blog/list';
var feedUrl = '/profiles/blog/feed';
getBlogs('#all-blogs', blogUrl, 5, feedUrl);
getBlogs('#feat-blogs', blogUrl+ '?tag=featured', 5, feedUrl+ '?promoted=1');
jQuery(".tab_content").hide();
jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
jQuery(".tab_content:first").show(); //Show first tab content
//On Click Event
jQuery("ul.tabs li").click(function() {
jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
jQuery(this).addClass("active"); //Add "active" class to selected tab
jQuery(".tab_content").hide(); //Hide all tab content
var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
jQuery(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
jQuery("#column1").append("<ul class='tabs'><li class='news'><a href='#all-blogs'>News</a></li><li class='featured-blogs'><a href='#feat-blogs'>Featured Blogs</a></li></ul><div class='tab_container'><div id='all-blogs' class='tab_content'></div><div id='feat-blogs' class='tab_content'></div></div>");
具体来说,该类不会添加以下行:
jQuery(".tab-container .module_body .postbody").last("a").addClass("continue-link");
我缺少什么吗?
-编辑- 这是受其影响的 html:
<div class="postbody">
<p><a href="link" target="_self"><img width="633" src="image"></a></p>
<p>Title</p>
<a href="link">Continue</a>
</div>
I have this code set up and everything works except the last line for some reason.
function getBlogs(element, url, limit, feed){
jQuery(element).load(url+ ' .blog_list .module_body:lt('+ limit+ ')', function(){
jQuery(this).prepend("<a class='home-rss' href='"+ feed+ "'></a>");
jQuery(this).append("<a class='view-all-blogs' href='"+ url+"'>View More »</a>");
// ** The following line isn't working: **
jQuery(".tab-container .module_body .postbody").last("a").addClass("continue-link");
});
}
var blogUrl = 'http://mysite.com/blog/list';
var feedUrl = '/profiles/blog/feed';
getBlogs('#all-blogs', blogUrl, 5, feedUrl);
getBlogs('#feat-blogs', blogUrl+ '?tag=featured', 5, feedUrl+ '?promoted=1');
jQuery(".tab_content").hide();
jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
jQuery(".tab_content:first").show(); //Show first tab content
//On Click Event
jQuery("ul.tabs li").click(function() {
jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
jQuery(this).addClass("active"); //Add "active" class to selected tab
jQuery(".tab_content").hide(); //Hide all tab content
var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
jQuery(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
jQuery("#column1").append("<ul class='tabs'><li class='news'><a href='#all-blogs'>News</a></li><li class='featured-blogs'><a href='#feat-blogs'>Featured Blogs</a></li></ul><div class='tab_container'><div id='all-blogs' class='tab_content'></div><div id='feat-blogs' class='tab_content'></div></div>");
Specifically, the class doesn't get added with this line:
jQuery(".tab-container .module_body .postbody").last("a").addClass("continue-link");
Is there anything I'm missing?
-edit-
Here's the html affected by it:
<div class="postbody">
<p><a href="link" target="_self"><img width="633" src="image"></a></p>
<p>Title</p>
<a href="link">Continue</a>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
从 docs 中,
last
方法不采用选择器。另外,在某些地方,您使用了类名
tab_container
,而在其他地方,您使用了tab-container
。那没有帮助。Try:
From the docs, the
last
method doesn't take a selector.Also not that in some places, you have used the class name
tab_container
and in others, you have usedtab-container
. That won't help.