【发布时间】:2017-11-14 13:15:01
【问题描述】:
我正在为一个学校项目学习 JQuery,并且在尝试遍历元素时需要帮助。
我有一个表格,显示到期余额和输入框,供用户输入自己的金额来支付余额。当用户输入金额时,我不希望金额超过到期金额。这是我目前所拥有的:
HTML:
<table>
<tr class="arow">
<td class="balance">
20.00
</td>
<td class="otheramount">
Other Amount: <input class="forminput" type="number">
</td>
</tr>
<tr class="arow">
<td class="balance">
30.00
</td>
<td class="otheramount">
Other Amount: <input class="forminput" type="number">
</td>
</tr>
<tr class="arow">
<td class="t-currentbalance">
40.00
</td>
<td class="otheramount">
Other Amount: <input class="forminput" type="number">
</td>
</tr>
</table>
JQuery:
$(".forminput").each(function() {
$(this).on("click change paste", function() {
var otherAmount = $(this).val();
var currentBalance = $(this).parent('td').prev('td.balance').html();
if (otherAmount > currentBalance) {
alert('You are over the balance amount!');
}
});
});
当我超过金额时,我一直不确定。我把它改成了父母,我得到了一堆随机数据。任何帮助将不胜感激,非常感谢!~
【问题讨论】:
标签: javascript jquery forms validation input