如何使用for循环从jsp获取jquery中的值?

时间:2013-11-06 07:16:56

标签: java jquery html jsp jstl

在我的Jsp中,值和类在循环中动态生成。

<div>
    <c:forEach var="interestTab" varStatus="loop" items="${interestParam}">
        <c:set var="interestFields" value="${fn:split(interestTab, '|')}" />
        <c:set var="maxAmt" value="${interestFields[1]}" scope="page" />
        <c:set var="minAmt" value="${interestFields[0]}" scope="page" />
        <c:set var="interestRate" value="${interestFields[2]}" scope="page" />
        <div class="personalcal-${loop.index}" style="display:hidden;">
            <div class="minamount-${loop.index}">
                ${interestFields[0]}
            </div>
            <div class= "maxamount-${loop.index}">
                ${interestFields[1]}
            </div>
            <div class= "intrate-${loop.index}">
                ${interestFields[2]}
            </div>
        </div>
    </c:forEach>

</div>

我想获取jquery中的所有值我该怎么办?如果它不是动态生成的类或id,那么我可以通过$(“。class”)。text()来获取它。但现在我的班级正在改变循环,我怎么能得到它?

1 个答案:

答案 0 :(得分:1)

put the below line in your jsp
<input type='hidden' value='${fn:length(interestParam)}' id="interestParamCount"/>

here is how to iterate in your js file

  for(counter = 0 ; counter < $('#interestParamCount').val();counter++){
      alert($('.minamount-'+counter).text());
      alert($('minamount-'+counter).text());
      alert($('intrate-'+counter).text());
  }