首先如下遍历可以取到很多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值,总觉得少了个触发事件,但是不懂得如何写,求高手指点!

解决方案 »

  1.   

    jquery选择器 #id
    根据给定的ID匹配一个元素。
    返回值 Element 不是Array<Element>
      

  2.   

     添加class元素 或者 根据层次机构选择元素集合吧!
      

  3.   

    <input type = "hidden" id = "funid" value = "${rows.funid }"/>
    无论循环多少次,你的id都没有变。所有的hidden id 都是funid
      

  4.   

    第一种用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(){
    }
      

  5.   


    $("#funid").each(function(){
    if(fid == "")
    {
    fid = $("#funid").val()+"/";
    }else
    {
    fid += $("#funid").val()+"/";
    }
    });
    alert(fid);
    });用name属性取id始终是一个值得呀
      

  6.   

    你应该ID=“id${id}”这样你的ID不会重复。阿门
      

  7.   


    <c:forEach var = "rows" items="${getAllList}">
      <input type = "hidden" id = "funid" name="funid" value = "${rows.funid }"/>
    </c:forEach>
    $("input[name=funid]").each(function(){
              alert($(this).val());
    })