在表行中查找班级
看一下这个表:
<table cellpadding="0" cellspacing="0" class="order_form">
<tr>
<th>Amount</th>
<th>Desc</th>
<th>Price</th>
<th>Total</th>
</tr>
<tr>
<td><input type="text" class="order_count" /></td>
<td>
<span class="order_desc">Middagstallerken</span>
</td>
<td>
<span class="order_price">1,15</span>
</td>
<td>
<span class="order_each_total"></span>
</td>
</tr>
[...]
</table>
输入金额后,我需要选择“order_price”类,并将其与输入“order_count”的值相乘,然后将其放入“order_each_count”中。我有很多这样的行,所以我需要找到该行中的下一个类。
我尝试过使用这样的函数,但没有结果:
<script type="text/javascript">
$(document).ready(function(){
$('.order_count').keyup(function() {
var each_price = $(this).prevUntil("tr").find("span.order_price").text();
});
});
</script>
我希望有人有一个好的解决方案:-)
Take a look at this table:
<table cellpadding="0" cellspacing="0" class="order_form">
<tr>
<th>Amount</th>
<th>Desc</th>
<th>Price</th>
<th>Total</th>
</tr>
<tr>
<td><input type="text" class="order_count" /></td>
<td>
<span class="order_desc">Middagstallerken</span>
</td>
<td>
<span class="order_price">1,15</span>
</td>
<td>
<span class="order_each_total"></span>
</td>
</tr>
[...]
</table>
Upon entering amount I need to select the class "order_price" and multiply it with the value of the input "order_count" and place it in "order_each_count". I have a lot of these rows so I need to find the next class in the row.
I have tried using some function like this but without result:
<script type="text/javascript">
$(document).ready(function(){
$('.order_count').keyup(function() {
var each_price = $(this).prevUntil("tr").find("span.order_price").text();
});
});
</script>
I hope someone have a good solution :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
closest()
而不是prevUntil
:记住使用
parseFloat
或parseInt
当尝试在计算中使用 DOM 中的数字时 - 默认情况下它们是字符串。Use
closest()
instead ofprevUntil
:Remember to use
parseFloat
orparseInt
when trying to use numbers from DOM in calculations – they're strings as default.