【问题标题】:How to get values in jquery from jsp using for loop?如何使用for循环从jsp获取jquery中的值?
【发布时间】:2013-11-06 07:16:56
【问题描述】:

在我的 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() 获取它。但是现在我的班级正在随着循环而改变我怎么能得到它??

【问题讨论】:

  • 我没有明白你的问题,你能解释一下吗
  • 在我的要求中,我想在我的 jquery 文件中获取值 ${interestFields[0]} ,${interestFields[1]},${interestFields[2]} 。如果它的类不是动态生成的,那么我可以通过这个 $('.minamount').text() 得到它。但是现在班级每次都在变化,那我怎么能得到它??

标签: java jquery html jsp jstl


【解决方案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());
  }

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 2017-09-17
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多