点击表格内一行,jquery获得此行第一个的input的value

我jsp有多个table。现在我要点击一行数据,是点一行的任何地方,就得到这一行的第一个input(checkbox)的 value。求js代码

<table class="grid2" id="stufflist" width="100%">
<thead>
<tr>
<th><input id="checkAllBox" name="checkAllBox" type="checkbox" onclick="ctlBox_click()"/></th>
<th>材料编码</th>
<th>材料名称</th>
<th>品牌</th>
<th>规格型号</th>
</tr>
</thead>
<c:forEach items="${vo}" var="item">
<tr style="height:35px" id="linkage">
<td>
<input type="checkbox" id="checkbox" name="checkbox" value="${item.pkId}"onclick="mailBox_click()"/>
</td>
<td><input type="text" value="${item.snStuff}" name="snStuff"/></td>
<td><input type="text" value="${item.naStuff}" name="naStuff"/></td>
<td><input type="text" value="${item.idBrand}" name="idBrand"/></td>
</tr>

</c:forEach>
</table>

$("#table tr").click(
$(this).child("td:eq(0)")//你试试这个。
each($(this).find("td"),function(){if($(this).index()==0){alert("我是这行里面第一个td");}})//两个找第一个td
找到td后,
$td.find(":check")//获取td中check空间。
$td.find(":check").attr("checked",true);//设置为true,如果不好使,就设置成
attr("checked","checked");
);
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-07-10

加一段Jquery代码即可,要先引用jquery库:

<script type="text/javascript">
    $(function () {
        $("table.grid2 tr").click(function () {
            var chkVal = $(this).find(":checkbox:first").val();
            alert(chkVal);
        });
    })
</script>

本回答被提问者采纳
第2个回答  推荐于2018-03-04
$('table tr').bind('click',function(
var val=$(this).find('input').first().val();
));本回答被网友采纳
相似回答