【发布时间】:2016-08-05 15:27:54
【问题描述】:
我使用 ajax 从我的网络服务器获取 json 数据。这些数据是视频网址和信息。
我怎样才能只显示前四个视频。然后隐藏其他视频(当它们已经加载到 html 时)。然后添加显示更多按钮功能以显示列表中的其他四个视频。
我这样显示视频列表:
$.each(data[2], function(i, row) {
var video_link = row.video_youtube_link;
var video_img = row.video_youtube_thumbnail;
var video_title = row.video_youtube_title;
var video_description = row.video_youtube_description;
var video_duration = row.video_youtube_duration;
var video_published = row.video_youtube_date_published;
var str = "<div class='video-list-wrapper'>";
str += "<div class='video-wrap'>";
str += "<div class='left-video-info'><a href=#null onclick=document.getElementById('video').src='http://www.youtube.com/embed/"+video_link+"'><img src="+ video_img +" width='100%' height='auto'></a><span class='video-duration'>"+parseDuration(video_duration)+"</span></div>";
str += "<div class='right-video-info'>";
str += "<div class='video-title'>"+video_title+"</div>";
str += "<div class='video-date'>"+ video_published +" ago</div>";
str += "</div>";//right-info
str += "</div>";//video-wrap
str += '</div>';
$('#video-list').append(str);
});
好的,我尝试用废品制作一个函数。它现在正在工作..
$(document).ready(function () {
var numvideo = $('.video-list-wrapper').length;
x=3;
$('.video-list-wrapper:lt('+x+')').show();
$('#loadMore').click(function () {
x= (x+5 <= numvideo) ? x+5 : numvideo;
$('.video-list-wrapper:lt('+x+')').show();
});
});
这是显示填充数据的示例: Sample
感谢您的帮助。
【问题讨论】:
-
你试过什么你的代码在哪里,你需要聘请网络开发人员吗?
-
你的链接无效,所以我们帮不了你,最好把javascript代码贴在这里
-
等一下,我会更新的。
-
您尝试创建加载更多功能的代码在哪里?