/** * Created by root on 3/25/16. */ $(document).ready(function(){ var bt=baidu.template; bt.LEFT_DELIMITER=''; var apiUrl = '/api/v1/'; var setTemplate = function(data){ console.log(data); var html=bt('t:result-list',{activities: data}); $('#container').prepend(html); descToggle(); $('.post-reply-submit').click(function(){ replyInsert(); }); }; var loadDataFromServer = function(id){ //getOpenId(function(openid){ $.ajax({ url: apiUrl + 'activities/' + id, dataType: 'json', success: function(data){ setTemplate(data.data); }, error: function(xhr,status,err){ console.log(err); } }); //}) }; loadDataFromServer(8686); //内容全部显示与部分隐藏 var descToggle = function(){ $(".post-all-content").each(function(){ var postHeight = $(this).height(); if (postHeight > 90){ $(this).parent().next().css("display","block"); $(this).parent().next().toggle(function(){ $(this).text("点击隐藏"); $(this).prev().css("height",postHeight); },function(){ $(this).text("点击展开"); $(this).prev().css("height",90); }); } }); } //点击回复按钮,插入回复内容 var replyInsert = function(){ var replyContent = $("#postInput").val(); if (!replyContent){ alert("请输入回复"); }else{ $(".post-reply-wrap:last").after('
'); $(".post-reply-content:last").append(replyContent); $("#postInput").val("");} } });