<meta charset=utf-8>
<table border=1 align=center width=80% id="mytable">
<tr>
<th>商品名称</th>
<th>数量(件)</th>
<th>单价(元)</th>
<th>运费(元)</th>
<th>合计</th>
</tr>
<tr>
<td>苹果</td>
<td>2</td>
<td>100</td>
<td>15</td>
<td></td>
<tr>
</table><br>
<input type="button" value=添加一行 onclick="myadd()"><br>
商品名称:<input type=text id="name"><br>
商品数量:<input type=text id="num"><br>
商品单价:<input type=text id="price"><br>
商品运费:<input type=text id="money"><br>
<script>
function myadd(){
var name=document.getElementById("name").value;
var num=parseInt(document.getElementById("num").value);
var price=parseInt(document.getElementById("price").value);
var money=parseInt(document.getElementById("money").value);
var newtr=document.createElement("tr");
newtr.innerHTML="<td>"+name+"</td><td>"+num+"</td><td>"+price+"</td><td>"+money+"</td><td>"+(num*price+money)+"</td>";
/* newtr.innerHTML="<td>"+price+"</td>";
newtr.innerHTML="<td>"+money+"</td>";
newtr.innerHTML="<td>"+result+"</td>";
newtr.innerHTML="<td>"+name+"</td>";*/
var mytable=document.getElementById("mytable");
mytable.appendChild(newtr);
document.getElementById("name").value="";
document.getElementById("num").value="";
document.getElementById("price").value="";
document.getElementById("money").value="";
}
</script>