我希望当用户点击删除图标时我需要隐藏输入的值"删除"上课,但我不明确可以有人指导我在哪里做错了
<table class="items-list">
<tr>
<th> </th>
<th>Product name</th>
<th>Product price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<!--Item-->
<tr class="item">
<td class="thumb"><a href="shop-single-item-v1.html"><img src="img/catalog/shopping-cart-thumb_2.jpg" alt="Lorem ipsum"/></a></td>
<td class="name"><a href="shop-single-item-v1.html">Wristlet</a></td>
<td class="price">715,00 $</td>
<td class="qnt-count">
<a class="incr-btn" href="#">-</a>
<input class="quantity form-control" type="text" value="2">
<a class="incr-btn" href="#">+</a>
</td>
<td class="total">2715,00 $</td>
<td class="delete"> <input type="hidden" name="row_id" value="123" > <i class="icon-delete"></i></td>
</tr>
</table>
我的jquery代码如下
$(document).on('click', '.shopping-cart .delete', function(){
var $target = $(this).parent().find('.row_id').val();
alert($target);
});
每次我跑来警告我都会收到错误&#34; undefined.tried许多不同的方式,但没有工作
答案 0 :(得分:0)
$(document).on('click', '.delete', function(){
var $target = $(this).find('input').val();
alert($target);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="items-list">
<tr>
<th> </th>
<th>Product name</th>
<th>Product price</th>
<th>Quantity</th>
<th>Total</th>
<th>action</th>
</tr>
<!--Item-->
<tr class="item">
<td class="thumb"><a href="shop-single-item-v1.html"><img src="img/catalog/shopping-cart-thumb_2.jpg" alt="Lorem ipsum"/></a></td>
<td class="name"><a href="shop-single-item-v1.html">Wristlet</a></td>
<td class="price">715,00 $</td>
<td class="qnt-count">
<a class="incr-btn" href="#">-</a>
<input class="quantity form-control" type="text" value="2">
<a class="incr-btn" href="#">+</a>
</td>
<td class="total">2715,00 $</td>
<td class="delete"> <input type="hidden" name="row_id" value="123" > <i class="icon-delete">Delete</i></td>
</tr>
</table>
&#13;
请查看工作代码。
我首先添加了一个新的<TH>
标记来显示删除按钮。
然后在jquery中我用 .find 来获取<TD>
的内部元素,并根据你的代码改变隐藏框的值
谢谢,希望它可以帮到你