我想获得具有类addition1::: 的值的总和
HTML 代码是
<tr >
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Inr</td>
<td align="right" class="heading"><?php if($inr!='')echo co($inr);else echo "0.00";?> </td>
<td> </td>
<td class="heading">ROE</td>
<td class="heading" ><span class="addition1"><?php if($inr!='')echo co($inr);else echo "0.00";?> </span> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Usd</td>
<td align="right" class="heading"><?php if($usd!='')echo co($usd);else echo "0.00";?> </td>
<td> </td>
<td><input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading1" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1">
<?php if($usd!='')echo co($usd);else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Gbp</td>
<td align="right" class="heading"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Eur</td>
<td align="right" class="heading"><?php if($eur!='')echo co($eur); else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe13" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"> <?php if($eur!='')echo co($eur); else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Other</td>
<td align="right" class="heading"><?php if($other!='')echo co($other);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($other!='')echo (co($other));else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
jQuery代码是
$(document).ready(function() {
$('#tables tbody>tr>td>input.heading#roe13').change(function() {
var k = $('#roe13').val();
$('#tables tbody>tr>td.heading3').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x=Math.round(parseFloat(v*k)*100) / 100;
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe11').change(function() {
var k = $('#roe11').val();
$('#tables tbody>tr>td.heading1').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x1=Math.round(parseFloat(v*k)*100) / 100;
return x1.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe12').change(function() {
var k = $('#roe12').val();
$('#tables tbody>tr>td.heading2').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x2=Math.round(parseFloat(v*k)*100) / 100;
return x2.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe14').change(function() {
var k = $('#roe14').val();
$('#tables tbody>tr>td.heading4').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x3=Math.round(parseFloat(v*k)*100) / 100;
return x3.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr').change(function() {
var sum = 0;
var regex = /\((\d+)\)/g;
$('span.addition1').each(function() {
matches = $(this).text().replace(/,/g, ''); alert(matches);
if( !isNaN( matches ) ){
sum += parseFloat(matches);
}
});
});
});
td 中的类名不能更改。我正在尝试获得具有类addition1的值的总和。在运行此代码时,将跳过 1 个值,例如,如果我更改一个值,例如 x1,那么由于 x1 生成的结果将被另外跳过。请帮帮我。