1. for循环中in的用法
for (var k in data) {
if (data[k].parent == null || data[k].parent == '') {
ids+=data[k].id+",";
}
}
2. 加载json文件
var id = "";
if(sort_classify==undefined||sort_classify==""){
sort_classify=$.ajax({
type : 'post',
url : root() + "/common/dictionary/dic_sort_classify.json",
async : false,
dataType:"json"
}).responseJSON;
}
for ( var i = 0; i < sort_classify.length; i++) {
if (sort_classify[i].code == code) {
id = sort_classify[i].id;
break;
}
}
3. ajax参数处理
param={};
param.sortType = "name";
param.page = 1;
param.typeCode = value;
$.ajax({
url : url,// 请求的url地址
type : "POST",
async : false,
data : param,
dataType : "json",
contentType : "application/x-www-form-urlencoded; charset=utf-8",
success : function(data) {
}
});
4.jsp页面引用路径
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
request.setAttribute("ctx",basePath);
%>
5.jstl的forEach及if
<c:forEach var="li" items="${route}">
<c:if test="${li.h=='' ||li.h==null }">
<li class="breadcrumb-item">${li.t}</li>
</c:if >
<c:if test="${li.h!=''&&li.h!=null }">
<li class="breadcrumb-item"><a href="${li.h}">${li.t}</a></li>
</c:if>
</c:forEach>
<core:if test="${resource.resource_type_code=='platform'}">
平台名称:
</core:if >
<core:if test="${resource.resource_type_code=='database'}">
数据库名称:
</core:if >
6.jsp页面日期。yyyy-MM-dd HH:mm:ss ,yyyy-MM-dd hh:mm:ss,大写H是24小时制,小写H是12小时制度
<time class="time ">更新日期:<fmt:formatDate value="${resource.created}" pattern="yyyy-MM-d"/></time>
7.fun
<c:if test="${fileList!=null&&fun:length(fileList)>0}">
<li>
<a href="javascript:void(0);">培训课件</a>
<div class="triangle1" ></div>
<div class="triangle2"></div>
</li>
</c:if>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="core" %>
<%@ taglib prefix="fun" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
8.offset的用法。填写内容为空,字数不够,特殊字符时的判断
var pattern =/[<>]/;
var top=$("#content").offset().top;
if($("#content").val()==""){
$.messager.alert({title:'提示', msg:'请填写评论内容!',icon: 'info',top:top});
return;
}
if($("#content").val().length<5){
$.messager.alert({title:'提示', msg:'评论内容不能少于5个字!',icon: 'info',top:top});
return;
}
if(pattern.test($("#content").val())){
$.messager.alert({title:'提示', msg:'评论有非法字符,请重新输入!',icon: 'info',top:top});
return;
}
// 元素相对于document的左位移
$("#haorooms-id").offset().left
// 元素相对于document的上位移
$("#haorooms-id").offset().top
$(".haorooms").click(function(){
x=$("p").offset();
$("#span1").text(x.left);
$("#span2").text(x.top);
});
// 设置元素相对于document的位移,该元素的position必须为非static值
$("#haorooms-id").offset({left:123,top:99});