我们如何使用jQuery获取动态元素的值?

时间:2016-11-01 06:18:36

标签: jquery

<td class="invert-price">${{$cartProduct->product_price}}</td>

JQuery

    $('.value-plus').on('click', function(){
    var divUpd = $(this).parent().find('.value'), newVal = parseInt(divUpd.text(), 10)+1;
    divUpd.text(newVal);
    var plus = $(".invert-price").html();
    if(plus.charAt( 0 ) === '$' )
    plus = plus.slice( 1 );
    plus = plus*2;
    $(".invert-price-").html('$'+plus);                                                                           
    });

我改变了td课程。

<td class="invert-price-{{$cartProduct->id}}">${{$cartProduct->product_price}}</td>

表 - &GT; TR

  @foreach($cartProducts as $cartProduct)
                <tr class="rem{{$cartProduct->id}}">
                    <td class="invert">{{$count}}</td>
                    <td class="invert-image"><a href="single.html">{{ Html::image('upload/product/'.$cartProduct->product_image, $cartProduct->product_image,['height'=> '200','width'=>'200','class'=>'img-responsive']) }}</a></td>
                    <td class="invert">
                         <div class="quantity"> 
                            <div class="quantity-select">                           
                                <div class="entry value-minus">&nbsp;</div>
                                <div class="entry value"><span>1</span></div>
                                <div class="entry value-plus active">&nbsp;</div>
                            </div>
                        </div>
                    </td>
                    <td class="invert">{{$cartProduct->product_name}}</td>
                    <td class="invert">$5.00</td>
                    <td class="invert-price-{{$cartProduct->id}}">${{$cartProduct->product_price}}</td>
                    <td class="invert">
                        <div class="rem">
                            <div class="close1" data-id="{{$cartProduct->id}}" data-token="{{ csrf_token() }}"> </div>
                        </div>
                        <script>$(document).ready(function(c) {
                            $('.close1').on('click', function(c){
                                                                var id = $(this).data("id");
                                                                 var token = $(this).data("token");
                                                         $.ajax({
                                                                                url: "removeCartItem/"+id,
                                                                                type: 'DELETE',
                                                                                dataType: "JSON",
                                                                                data: {
                                                                                    "id": id,
                                                                                    "_method": 'DELETE',
                                                                                    "_token": token,
                                                                                },
                                                                               success: function ()
                                                                                {
                                                                                    $('.rem'+ id).fadeOut('slow');
                                                                                }
                                                                                });
                                });
                            });
                       </script>
                    </td>
                </tr> <?Php $count++; ?>
                                    @endforeach

我想要的是,当我点击增量按钮的价格在我的情况下加倍了价格每个价格元素(td)加倍。所以我用td class class =“invert-price - {{$ cartProduct-&gt; id}}”添加了id。我不知道如何使用jquery获取动态元素的值。所以请帮助我。

0 个答案:

没有答案