jsp中常用的和方法
jsp中常用的<c:if>判斷非空的方法:
<c:if test="${empty obj.glyhf}">為空</c:if> //為空顯示
<c:if test="${not empty obj.glyhf}">不為空</c:if> //不為空顯示
<c:if>判斷表單欄位,重複${${}}時:這時候直接把裡層的${}去掉就可以了。
<c:if test="${prostate=='WC'&& yhpjlist.items[0].pjnr==null }">
<tr>
<td style="width: 50%;" colspan="2">
<em class="gw_h2">評價內容:</em> <em> <f:field column="SBBX_YHPJ.pjnr" value="${yhpjlist.items[0].pjnr}"
</td>
</tr>
<tr>
<td style="width: 50%;" colspan="2">
<em class="gw_h2">滿意度:</em> <em> <f:field column="SBBX_YHPJ.myd" value="${yhpjlist.items[0].myd}"> </f:field></em>
</td>
</tr>
</c:if>
js動態新增表格,將資料存入子表中,然後用<c:forEach>取出時:
function addsyhc(){
var unid=Math.uuid();
var tr='<tr id="'+unid+'" class="mytr" valign="middle">';
tr+='<td width="25%" align="center">';
tr+='<input comments="耗材分類" style="width:130px" id="hcfl'+unid+'" name="SBBX_SYHC'+unid+'.hcfl" notnull="false" nullalert="" type="text" value="">';
tr+='<input type="hidden" name="SBBX_SYHC.unid" value="'+unid+'" /> ';
tr+='<input type="hidden" name="SBBX_SYHC'+unid+'.parentid" value="${formlist.items[0].unid}" /> ';
tr+='</td>';
tr+='<td width="25%" align="center">';
tr+='<input comments="耗材名稱" style="width:130px" id="SBBX_SYHC'+unid+'.hcmc" name="SBBX_SYHC'+unid+'.hcmc" notnull="false" nullalert="" type="text" value="">';
tr+='</td>';
tr+='<td width="25%" align="center">';
tr+='<input comments="耗材數量" style="width:120px" id="SBBX_SYHC'+unid+'.hcsl" name="SBBX_SYHC'+unid+'.hcsl" notnull="false" nullalert="" type="text" value="" />';
tr+='</td>';
tr+='<td align="center" width="10%">';
tr+=' <a href="javascript:void(0);" style="color:red" onclick="deletegzlb(\''+unid+'\');">刪除</a>';
tr+='</td>';
$("#syhctable").append(tr);
}
function deletegzlb(unid){
$("#"+unid).remove();
var value="SBBX_SYHC,"+unid;
var delteInput='<input type="hidden" name="delete.unid" value="'+value+'"/>';
$("#deleteem").append(delteInput);
}
在jsp中用<for:each>取出來:
<table id="syhctable" border="0" cellpadding="0" cellspacing="0" width="500px">
<tr>
<td height="25" align="center" >耗材分類</td>
<td height="25" align="center">耗材名稱</td>
<td height="25" align="center">數量</td>
<td height="25" align="center"><a style="color:green;font-weight:bold;" href="javascript:void(0);" onclick="addsyhc();" >新增</a></td>
</tr>
<c:forEach var="syhc" items="${syhclist.items}" varStatus="status">
<tr id="${syhc.unid}" class="mytr" valign="middle">
<td width="150px" height="25" align="center">
<input comments="耗材分類" id="hcfl${syhc.unid}" name="SBBX_SYHC${syhc.unid}.hcfl" notnull="false" nullalert="" type="text" value="${syhc.hcfl}" />
<input type="hidden" name="SBBX_SYHC.unid" value="${syhc.unid}" />
</td>
<td width="150px" height="25" align="center">
<input comments="耗材名稱" id="SBBX_SYHC${syhc.unid}.hcmc" name="SBBX_SYHC${syhc.unid}.hcmc" notnull="false" nullalert="" type="text" value="${syhc.hcmc}" />
</td>
<td width="150px" height="25" align="center">
<input comments="耗材數量" id="SBBX_SYHC${syhc.unid}.hcsl" name="SBBX_SYHC${syhc.unid}.hcsl" notnull="false" nullalert="" type="text" value="${syhc.hcsl}" />
</td>
<td align="center" height="25">
<a style="color:red" href="javascript:void(0);" onclick="deletegzlb('${syhc.unid}');">刪除</a>
</td>
</tr>
</c:forEach>
</table>