jquery:gt问题。。试图展示更多
我想在一个网站上设立一个新闻区。。每个项目都包含在自己的名为.newsitem的div类中。我希望能够单击.showmorenews以显示其他项目。我做错了什么?我搞不懂,而且我对jquery还相当陌生。谢谢jquery:gt问题。。试图展示更多,jquery,Jquery,我想在一个网站上设立一个新闻区。。每个项目都包含在自己的名为.newsitem的div类中。我希望能够单击.showmorenews以显示其他项目。我做错了什么?我搞不懂,而且我对jquery还相当陌生。谢谢 $(document).ready(function(){ var remixnewsshow = 2; remixnewsshow--; //fix variable since the index for :gt starts at 0 $(".newsitem
$(document).ready(function(){
var remixnewsshow = 2;
remixnewsshow--; //fix variable since the index for :gt starts at 0
$(".newsitem:gt(" + remixnewsshow + ")").hide();
$(".showmorenews").click(function () {
remixnewsshow++;
$(".newsitem:gt(" + remixnewsshow + ")").show();
});
});
html:
近期新闻
简
16
文本文本文本
简
2.
文本文本文本
十月
3.
文本文本文本
我想你想要的实际上是把第二个gt
改成eq
:
$(".showmorenews").click(function () {
remixnewsshow++;
$(".newsitem:eq(" + remixnewsshow + ")").show();
});
您所做的工作的问题是,您最初显示2个元素,然后单击时,您将显示大于2的所有元素,这是所有其余元素。您只想显示下一个元素。它在做什么,您希望它做什么?查看您的代码,它应该显示前两个新闻项,然后每次单击showmorenews时再显示一个。这非常有用!非常感谢。我的第一个问题是。。不到一分钟就回答了!太神了
$(".showmorenews").click(function () {
remixnewsshow++;
$(".newsitem:eq(" + remixnewsshow + ")").show();
});