嗨我有这个从以前的帖子修复的表格。
<form id="eForm" action="">
<table class="fMain" border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr class="ist">
<td>In work</td>
<td>09/25/2013</td>
<td><input type="text" value="3500.00" name="salesS" class="totalS fo" readonly=""></td>
<td ><input type="text" value="23.00" name="cusS" class="cusS form-field-tiny readonly" readonly=""></td>
<td>0.66%</td>
</tr>
<tr class="ist">
<td>In work</td>
<td>09/25/2013</td>
<td><input type="text" value="2445.00" name="salesS" class="totalS fo" readonly=""></td>
<td ><input type="text" value="444.00" name="cusS" class="cusS form-field-tiny readonly" readonly=""></td>
<td>0.66%</td>
</tr>
</tbody>
</table>
</form>
我正在使用以下jQuery来做一些格式化。
$('.eForm tr.ist').each(function () {
var num = $(this).find('#salesS').val();
var cNum = $(this).find('#cusS').val();
alert(num);
alert(cNum);
document.getElementById('salesS').value = pC(num);
document.getElementById('cusS').value = pC(cNum);
});
工作正常所有值都处理得很好。但是当它使用时更新值 以下行不会更新当前行。它只是更新了第一行。
document.getElementById('salesS').value = pC(num);
document.getElementById('cusS').value = pC(cNum);
我试过这个
$(this).find('#cusS').val()=pC(num);
它不起作用。请让我知道如何修复它,以便更新当前行中的值。谢谢
答案 0 :(得分:0)
你的jQuery非常错误。原因如下:
$('.eForm tr.fMain').each(function () { // YOU GOT NO TR WITH THAT CLASS, It'S A TABLE
var num = $(this).find('#salesS').val(); // YOU GOT NO ELEMENT WITH "salesS" ID
var cNum = $(this).find('#cusS').val();// YOU GOT NO ELEMENT WITH "cusS" ID
alert(num);
alert(cNum);
document.getElementById('salesS').value = pC(num);
document.getElementById('cusS').value = pC(cNum);
});
这段代码也错了:
$(this).find('#cusS').val()=pC(num);
这可能是有效的(如果你有cus5 id的输入
$(this).find('#cusS').val(pC(num));
现在你想要的是:
$('.eForm tr.ist').each(function () {
var inputSales = $(this).find('input[name=salesS]');
var inputCus = $(this).find('input[name=cusS]');
inputSales.val(pC(inputSales.val());
inputCus.val(pC(inputCus.val());
});