首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

JS 获取table上控件的值

2012-08-10 
JS 获取table下控件的值tabletrtdinput typetext value123//tdtdinput typetext va

JS 获取table下控件的值
<table>
<tr>
<td><input type="text" value="123"/></td>
<td><input type="text" value="321"/></td>
<td><input type="text" value="254"/></td>

<td><input type="text" value="123"/></td>
</tr>
<tr>
<td><input type="text" value="78"/></td>
<td><input type="text" value="5"/></td>
<td><input type="text" value="45"/></td>
<td><input type="text" value="54"/></td>
</tr>

<td><input type="text" value="4"/></td>
<td><input type="text" value="44"/></td>
<td><input type="text" value="4445"/></td>
<td><input type="text" value="44477"/></td>
</tr>

</table>


我想让标红的那个几个单元格值相加,但是不知道怎么取得他的值, 我想用循环, document.getElementById("Table1").rows[1][11].innerHTML; 这样只能取得不带控件的值吧,带控件了就取不到了,这个表格是动态生成的,表格ID没有规律。该怎么取呢

[解决办法]
JQ

HTML code
    <script type="text/javascript">        $(document).ready(function () {            $("table tr td:nth-child(3)").each(function () {                var val = $("input", this).val();            })        })    </script>
[解决办法]
用jQuery
var total=0;
$("#"Table1 tr").each(function(){
total+=parseInt($(this).find("input[type='text']")[2].val());
});

热点排行