<table>
<thead>
<tr>
<th type="tc" name="price"onclick="test(this)">单价(元)</th>
<th type="tc" name="num" >数量</th>
<th type="tx" name="totalprice >总价(元)</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
在方法test(this)中 如何实现 把 类型 [type=tc] 的值 相乘,所得到的值赋给 [type="tx"] ,其中type属性是我自定义的。 [type=tc] * [type=tc] * ....*[type=tc] =[type=tx] 就是这么个意思。
解决方案 »
- 懂正则表达式的请进
- javascript:history.go window.onload 表单提交
- javascript 变量与字符串的问题
- showModelessDialog出来的窗体为何无法提交表单?
- 怎样判断网页上有没有出现滚动条?
- qiushuiwuhen(秋水无恨) 能再回答一个问题吗?
- 怎么样重写Dom的方法函数?
- 请问如何使用jquery cookie保存输入框中的值,并在页面右侧的div中显示出来?
- jq 如何使用 delegate 为表格某列未来的td添加“blur”事件?
- 求问个html中表格显示的问题
- JQuery如何实现这种简单的效果?新人求助。
- 怎么样显示一个随机数?
<head id="Head1" runat="server">
<title>无标题页</title>
<script type="text/javascript">
function test(th) {
table = th.parentNode;
while (table.tagName != "TABLE")
table = table.parentNode;
for (i = 1; i < table.rows.length; i++) {
table.rows[i].cells[2].innerHTML = parseFloat(table.rows[i].cells[0].innerHTML) * parseFloat(table.rows[i].cells[1].innerHTML);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<thead>
<tr>
<th type="tc" name="price" onclick="test(this)">单价(元)</th>
<th type="tc" name="num">数量</th>
<th type="tx" name="totalprice">总价(元)</th>
</tr>
</thead>
<tbody>
<tr>
<td>33</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>12</td>
<td>5</td>
<td></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
var p=o.parentNode.getElementsByTagName("th");
var totalprice=1;
for(i=0;i<p.length;i++){
if(p[i].getAttribute("type")=='tc'){
totalprice*=parseFloat(p[i].innerHTML);
}else{
p[i].innerHTML=totalprice;
}
}
}
如果每次需计算的结构是和下面的一样的话,那使用上面的
<tr>
<th type="tc" name="price"onclick="test(this)">单价(元)</th>
<th type="tc" name="num" >数量</th>
<th type="tx" name="totalprice >总价(元)</th>
</tr>