首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

遍历取值有关问题

2012-02-13 
遍历取值问题首先如下遍历可以取到很多idc:forEach var rows items${getAllList}input type

遍历取值问题
首先如下遍历可以取到很多id 
<c:forEach var = "rows" items="${getAllList}">
  <input type = "hidden" id = "funid" value = "${rows.funid }"/>
</c:forEach>

但我想用jquery取得每一个遍历的id值
  <script type="text/javascript">
$(function() {
var fid = "";
$("#funid").each(function(){
if(fid == "")
{
fid = $("#funid").val()+"/";
}else
{
fid += $("#funid").val()+"/";
}
});
alert(fid);
});
</script>

但是为什么总是只取到第一个id值,总觉得少了个触发事件,但是不懂得如何写,求高手指点!



[解决办法]
第一种用varStatus--->va.index来区分ID
<c:forEach var = "rows" items="${getAllList}" varStatus="va">
<input type = "hidden" id = "funid" value = "${rows.funid }"/>
</c:forEach>


第二种方法(使用name来标示input控件):
<c:forEach var = "rows" items="${getAllList}" >
<input type = "hidden" name = "funid" value = "${rows.funid }"/>
</c:forEach>
在Script你可以写成:
$("input[name="funid]").each(function(){
}

[解决办法]

Java code
$("#funid").each(function(){if(fid == ""){fid = $("#funid").val()+"/";}else{fid += $("#funid").val()+"/";}});alert(fid);});用name属性取。。。id始终是一个值得呀。。。
[解决办法]
HTML code
<c:forEach var = "rows" items="${getAllList}">  <input type = "hidden" id = "funid" name="funid" value = "${rows.funid }"/></c:forEach> 

热点排行
Bad Request.