jsp中常用的<c:if>和<c:forEach>方法

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}"> </f:field></em>
</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" οnclick="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);" οnclick="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);" οnclick="deletegzlb('${syhc.unid}');">删除</a>
</td>
</tr>
</c:forEach>
   </table>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值