<#if content?length gt 100> ${content[0..100]}... <#else> ${content} </#if>
freemarker里面不能包含>< 所以要用到大於和小於,就要用gt,lt gt是大於,lt是小於, >= gte , <= lte
private Map<Integer,String> storePhotoUrl;
storePhotoUrl 為map結構,在html頁面中,通過list進行遍歷,通過??判斷是否有值,通過?size得到集合的長度
通過 <#list 0..6 as t >
{t}
</#list >
會輸出0123456
<#if storePhotoUrl??> <div style="float: left;height:200px;position:relative;text-align:center;margin-left:120px;"> <#list storePhotoUrl?keys as st> <div style="float: left;height:200px;position:relative;text-align:center;margin-right:5px;"> <img src="${storePhotoUrl.get(st)}" width="100" height="100" id="img${st}"> <br/> <input type="hidden" name="picnames" id="fs_img${st}" value="${storePhotoUrl.get(st)}" /> <input type="hidden" name="status" value="2" id="fs_status${st}" /> <input type="file" id="goods${st}" fs="${st}" status="修改" /> <input type="button" name="clean" value="清除" fs="${st}" class="del_addgoods"/> </div> </#list> <#if storePhotoUrl?size lt 7> <#list (storePhotoUrl?size+1)..7 as t> <div style="float: left;height:200px;position:relative;text-align:center;margin-right:5px;"> <img src="" name="img${t}" id="img${t}" width="100" height="100"> <br/> <input type="hidden" name="goods_fs" id="fs_img${t}" fs="${t}"/> <input type="hidden" name="status" value="2" id="fs_status${t}" /> <input type="file" id="goods-${t}" fs="${t}" status="上傳" /> <input type="button" name="clean" value="清除" fs="${t}" class="del_addgoods"/> </div> </#list> </#if> <#else> <div style="float:left;margin-left:100px" class="goods_image" id="goods_image"> <input type="file" value="批量上傳" id="allFile" status="批量上傳"/><br> <span><font color="red">批量上傳只適用於第一次上傳且總和能上傳七個。</font></span><br/> <#list 0..6 as t> <div style="float: left;height:200px;position:relative;width:100px;text-align:center;margin-right:5px;"> <img src="空" name="img${t}" id="img${t}" width="100" height="100"/> <br/> <input type="hidden" name="goods_fs" id="fs_img${t}" fs="${t}"/> <input type="hidden" name="status" value="2" id="fs_status${t}"/> <input type="file" id="goods${t}" fs="${t}" status="上傳"/> <input type="button" name="clean" value="清除" fs="${t}" class="del_addgoods"/> </div> </#list> </#if>
$("input[name='clean']").click(function(){
var fs=$(this).attr("fs");
console.log("-------fs--------"+fs);
$("#img"+fs).attr("src","");
//$("#fs_status"+fs).val("0");
$("#fs_img"+fs).attr("name","del_pic");
$("#fs_img"+fs).val("");
});
這段js的代碼意思是
先通過jQuery選擇器,綁定name=clean的input ,增加一個點擊事件,當點擊在這個input按鈕上時,獲取當前點擊的屬性為fs的值,這個值就是遍歷出來的0123456中的一個,通過這個值,再進行字符串的拼接,就可以獲取當前input按鈕id