从for循环生成的td标签中获取输入标签的值

时间:2014-05-03 09:57:13

标签: jquery

我想获得其元素的当前价格已经改变了。 我只能改变第一个元素的价格,而不是其他元素的价格 请帮助我从数量的下拉菜单中获取所选元素的数量。

 <script type="text/javascript"> //quantity retrival
    $(document).ready(function() {

    $('.quantityx').change(function(){
        alert("message");

        var tot =$('#pricexx').val()* this.value;
         alert(this.parent.find('input[name=pricexx]').val());

         });

    });
    </script>

    <table id="mytable">

                    <%
                        int i = 0;
                        while (it.hasNext()) {
                            i++;
                            Product_List PL = (Product_List) it.next();

                            list.add("" + PL.getProduct_id());
                            String order = list.toString();
                            session.setAttribute("orders", order);
                    %><tr class="row">



                        <td class="delete">
                            <div class="centererer">
                                <form action="PDelete" method="get">
                                    <input type="hidden" name="p_id" value="<%=PL.getProduct_id()%>"
                                        id="Product_id" /> <input type="submit" class="close">
                                </form>
                            </div>
                        </td>
                        <td class="image"><img src="<%=PL.getImage()%>" width="86"
                            height="86" /></td>
                        <td class="name"><%=PL.getBrand()%> <%=PL.getDetail()%></td>
                        <td class="size"><%=PL.getCloth_size()%></td>

                        <td class="price">&#8377;<input name="pricexx" type="text" disabled="disabled" value="<%=PL.getPrice()%>"></td>
                        <td class="quauntity">
                        <select class="quantityx">
                <option value="1" selected="selected">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
            </select>


                            </td>
                        <%!int totalprice, netprice = 0,quant=1;%>
                        <%
                            totalprice = quant * PL.getPrice();
                        %>
                        <%
                            netprice = totalprice + netprice;
                        %>

                        <td class="price">&#8377;<input id="tp" type="text" disabled="disabled" value="<%=totalprice%>"></td>

                    </tr>
                    <%
                        }
                    %>
                </table>
                <!--         -->
                <input type="hidden" value="<%=list.toString()%>" name="array" /> <br />
                <br />
                <br />
                <br />
                <table>
                    <tr>
                        <!-- <td  class="size"></td> -->
                        <td class="total">TOTAL <span class="pricex">&#8377;<%=netprice%></span></td>


                    </tr>
                </table>

1 个答案:

答案 0 :(得分:0)

您的选择器无法获取当前input[name=pricexx]。你应该这样做

var input = $(this).parent().parent().find('input[name=pricexx]');
var tot = input.val() * this.value;