触发器 评论折叠显示(jquery)
触发器 评论折叠显示(jquery)
子页面 :
@if(Model?.count>0)
{
var i=1;
var n=model.count-2
var isHiden = n>0;
foreach(var item in Model)
{
var hiddenitem = isHiden && i++<n
<div class="comment" @(hiddentm?"date-conment-hide="+item.SubjectId:"")>
<div class="pull-left">
<img class="comment-userpic img-circle" src="@item.UserPic" />
</div>
<div class="comment-right">
<span class="comment-title">
@(item.RealName ?? item.UserName)
</span>
<i class="comment-addtionInfo">@Html.DateTime(item.AddDate)</i>
<p class="comment-text">
@item.Content
</p>
</div>
<div class="clearfix"></div>
</div>
}
}
if (Model?.Count > 2)
{
<a href="#" data-comment-extend="@(Model[0].SubjectId)">展开</a>
}
<script>
$('[date-conment-hide =@(Model[0].subjectId)]').hiden();
</script>
主页面:
$('table').on('click','[data-comment-extend ]',function(){
var self=$(this);
var sid = self.attr('data-comment-extend');
self.html()=="展开"?self.text("折叠"):self.text("展开");
$('[date-conment-hide='+sid+' ]').slideToggle()
retun false;
});
滴水能把石穿透,成事功到自然成