计算表列

时间:2018-08-13 17:56:15

标签: javascript jquery html calculated-columns

我正在计算要创建的表中的列。我需要sum字段来累加从表单创建的值,该表单在提交后为表格创建新行。有什么办法可以让我累加列总和?每次运行函数updatetable()时,都会创建另一个表行,这些行是我需要计算的行……当前,该列保留一个“ 184”作为进行计算的位置。

    <!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>The real test</title>
  <link rel="stylesheet" href="html_testing.css">

  <script type="text/javascript"> <!--

 var tabBody, row, cell;
 function updateTable(){
     tabBody=document.getElementById("joe$");
     row=document.createElement("tr");
     row.setAttribute("id","js");
     cell = document.createElement("td");
     cell.innerHTML=document.forms['leds'].elements[2].value;
     row.appendChild(cell);
     if(tabBody.childNodes.length==17)
       tabBody.removeChild(tabBody.childNodes[0])
     tabBody.appendChild(row);
 }
   function updateTable1(){
     tabBody=document.getElementById("joe");
     row=document.createElement("tr");
     cell = document.createElement("td");
     cell.innerHTML=document.forms['leds'].elements[3].value;
     row.appendChild(cell);
     if(tabBody.childNodes.length==17)
       tabBody.removeChild(tabBody.childNodes[0])
     tabBody.appendChild(row);
 }



    function myFunctionJoe(){
        updateTable();
        updateTable1();
        }

    function moneymoney(){
    ('#joe$ tr:first td').each(function(){
   var $td = $(this);  

    var colTotal = 0;
    $('#joe$ tr:not(:first,.totalColumn)').each(function(){
        colTotal  += parseInt($(this).children().eq($td.index()).html(),10);
    });

    $('#joe$ tr.totalColumn').children().eq($td.index()).html('Total: ' + colTotal);
});
}

 </script>

 <body>
 <h2>Legion of Roar:</h2>
<form name="leds" id="ledSend" action="" onsubmit="return false;">
Lamp Control: <input type="radio" name="led" value="0" checked />Off
              <input type="radio" name="led" value="1" />On<br>
Winning Bid: <input type="text" name="timer" placeholder="Bid..." /><br>
Player Drafted: <input id="name" type="text" name="user" placeholder="Player Name..." /><br>
Player Position: <input id="name" type="text" name="user" placeholder="Position..." /><br>
<br>
<input type="submit" value="Joe" onclick="myFunctionJoe();"/>

<h1>Testing some skills</h1>
<fieldset>
<table border ='1' class="inlineTable">
<thead><tr><th>Joe</th></tr></thead>
<thead><tr><th>200</th></tr></thead>
<tr class="totalColumn">
        <td class="totalCol">Spent:</td>
    </tr>
<tbody id="joe"><tbody>
</table>
<table border ='1' class="inlineTable">
<thead><tr><th>$</th></tr></thead>
<thead><tr><th>184</th></tr></thead>
<tr class="totalColumn">
        <td class="totalCol">Spent:</td>
    </tr>
<tbody id="joe$"><tbody>
</table>
</body>

</html>

0 个答案:

没有答案