日期:2014-05-17  浏览次数:20742 次

判断表格是否为空
JScript code

           <table align="center" border="1" id="filesTable" style="display:none">
           <th>name</th>
           <th>size</th>
           <th>status</th>
           </table>


JSP中的表格,点击submit后,如何判断是否为空,如果不为空的话,如何在后台循环取值
新人求教。。

------解决方案--------------------
判断表格是否为空,可以根据表格的rows属性来判断表格里面有多少行,如果只有一行表头的话,自然就是空了。

但是如果你要将表格里面的值传到后台去的话,还是需要用表单元素的。。否则的话,就需要你用js将表格里面的值都提取出来,再发送之后台。。。也就是说,后台是不能直接遍历你的jsp上面的表格里面的数据的。
------解决方案--------------------
给th设置一个属性id 然后用document.getElementById("").innerText 取得
<table align="center" border="1" id="filesTable" style="display:none">
<th id="username">name</th>
<th>size</th>
<th>status</th>
</table>

js:
document.getElementById("username").innerText ;
------解决方案--------------------

比如:
<table align="center" border="1" id="filesTable" style="display:none">
<tr>
<td><div id = "name">namess</div></td>
</tr>
</table>

在js中通过var str = document.getElementById("name").innerText;

这里就取到了namess
------解决方案--------------------
在table里搜tr就可以了,没有tr就说明是空的。。。
------解决方案--------------------
貌似你action中只要有你要传值的属性getter/stter方法 action中就能自动包装吧。。