HTML中常用的js技巧和方法
2017-04-11 08:35
288 查看
以评论功能为例
1.ajax动态加载评论列表
js:
html:
2.点击评论按钮,页面滚动到评论框,评论框获取焦点
1.ajax动态加载评论列表
js:
// 加载评论列表 var postId = $("#postId").html(); $.post("post/commentList.action?postId="+postId, function(data) { $("#comment-list").html(data); });
html:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <%--comment list--%> <c:forEach items="${page.beanList}" var="comment" varStatus="status"> <li class="media"> <a class="pull-left" href="ta/show.action?userId=${comment.userId}"> <img class="thumbnail img-responsive center-block" src="${comment.portrait}" style="width: 65px"/> </a> <div class="media-body"> <a href="javascript:;" class="btn btn-primary btn-xs pull-right reply" onclick="replyComment('回复 #${(page.pageIndex-1)*10 + status.index + 1} ${comment.trueName}:')">回复 </a> <h4>#${(page.pageIndex-1)*10 + status.index + 1} ${comment.trueName}</h4> <small class="text-muted"><fmt:formatDate value="${comment.createTime}" pattern=" Y-M-d HH:mm "></fmt:formatDate></small> <p>${comment.content}</p> </div> </li><!-- media --> </c:forEach> <%--btn-load-more--%> <c:if test="${page.beanList.size()>=10}"> <button class="btn btn-default btn-sm btn-block" onclick="loadMoreComment(${page.pageIndex+1})" id="btn-load-more"> <i class="fa fa-plus-square-o"></i> 加载更多 </button> </c:if>
2.点击评论按钮,页面滚动到评论框,评论框获取焦点
$("html,body").animate({scrollTop:$("#comment-content").offset().top},500);//500是ms,也可以用slow代替
相关文章推荐
- 可以把一些常用的方法,写入js文件,引入html界面
- js,jquery常用拼接html方法
- JS中常用操作技巧(页面动态增加div,contain方法扩展,JSON对象鱼字符串转换)
- js,Jquery,ajax常用方法技巧
- html js 常用技巧
- HTML、js:如何利用Location对象的常用属性和方法重新加载、刷新页面
- js,Jquery,ajax常用方法技巧
- JS操作HTML节点常用到的方法和节点属性
- html js 常用技巧
- Html的部分常用技巧
- 常用HTML页面技巧大全
- asp常用数据库连接方法和技巧
- html&js 在firefox与IE中呈现存在差异的解决方法总结
- 常用的一些JS技巧
- web开发常用js功能性小技巧
- Html常用技巧
- JSP编辑技巧,常用方法
- 常用HTML技巧
- ASP常用数据库连接及操作的方法和技巧
- html&js技巧 ---摘自sdlcn的专栏