0
<form>
  <table width="660" border="0" class="DarkButtonStyleMedium">
    <tr>
      <td width="299">&nbsp;</td>
      <td width="332" rowspan="11"><img src="Images/PCD-HOLES.png" width="350" height="353"
                                        class="ButtonStyleMedium"/></td>
    </tr>
    <tr>
      <td>
        <div align="right">PITCH CIRCLE <span
                                           class="GeneralPageTextWhite">DIAMETER (PCD):</span><span
                                                                                                 class="GeneralPageText">:
            <input name="diameter" type="Number" class="ButtonStyleMedium" id="diameter"
                   value="" size="12"/>
        </span></div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
        <div align="right"><span class="GeneralPageTextWhite"> NUMBER OF HOLES:
            <input name="number" type="Number" class="ButtonStyleMedium" id="number"
                   value="" size="12"/>
        </span></div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
        <div align="right"><span class="GeneralPageTextWhite">START ANGLE (A):
            <input name="startangle" type="Number" class="ButtonStyleMedium" id="startangle"
                   value="" size="12"/>
        </span></div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
        <div align="right"><span class="GeneralPageText">
            <input type="button" class="ButtonStyleMedium" onclick="calculateAll();" value='SOLVE'/>
        </span></div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
        <div align="right"><span class="GeneralPageText">
            <input type="button" class="ButtonStyleMedium" onclick="clearAll();clearTable();" value='RESET'/>
        </span></div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>

  <div class="ButtonStyleAnswer">
    <table id="resultTable" width=600 border="0.5">
      <colgroup>
        <col width=200>
      </colgroup>
      <tr>
        <th>
          <div align="left" width=200 >HOLE NUMBER</div>
        </th>
        <th>
          <div align="left" width=200 >X CO-ORDINATE</div>
        </th>
        <th>
          <div align="left" width=200 >Y CO-ORDINATE</div>
        </th>
      </tr>
      <tr>
        <td height="19" colspan="3">
          <div align="center"></div>
          <div align="center"></div>
          <div align="center"></div>
        </td>
      </tr>
    </table>
  </div>
  <p>&nbsp;</p>
</form>
<p>&nbsp;</p>
</div>
<script>


function calculateAll() {
    var diameter = Number(document.getElementById("diameter").value);
    var number = Number(document.getElementById("number").value);
    var startangle = Number(document.getElementById("startangle").value);
    do {
        var holenumber = 0;
        var boltholenumber = holenumber + 1;
        var radius = diameter / 2;
        var k = (holenumber * (360 / number)) + startangle;
        var xresult = radius * Math.cos(k);
        var yresult = radius * Math.sin(k);
        var table = document.getElementById("resultTable");
        var row = table.insertRow(-1);
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(1);
        cell2.innerHTML = xresult.toFixed(5);
        cell3.innerHTML = yresult.toFixed(5);
        cell1.innerHTML = boltholenumber.toFixed(0);
        holenumber++;
    }
    while (holenumber > number);
}

function clearAll() {
    document.getElementById("diameter").value = "";
    document.getElementById("number").value = "";
    document.getElementById("startangle").value = "";
    document.getElementById("boltholenumber").value = "";
    document.getElementById("xresult").value = "";
    document.getElementById("yresult").value = "";
}
function clearTable() {
    var elmtTable = document.getElementById('resultTable');
    var tableRows = elmtTable.getElementsByTagName('tr');
    var rowCount = tableRows.length;
    for (var x = rowCount - 1; x > 0; x--) {
        elmtTable.removeChild(tableRows[x]);
    }
}


</script>

你好

我有一个两部分的问题,但我不确定这是否允许。第一部分是我只能从 do/while 循环中获得一行输出,这是因为我正在写入相同的单元格,尽管我在循环中使用 table.insertRow(-1)。第二部分是我无法使用 clearAll 函数从表中清除一行结果,我不明白为什么。我用过 Jsfiddle 并没有得到任何提示。

4

0 回答 0