jQuery怎么获取table的某一格的值

html-css06

jQuery怎么获取table的某一格的值,第1张

参考代码自己改改,用了jQuery

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<script type="text/javascript">

$(function(){

$('.btn').click(function(){

alert($(this).parent().parent().find('td:eq(0)').attr('val'))

})

})

</script>

</head>

<body>

<table id="tab">

<tr>

<td val="1">111</td><td>6666</td><td><input type="button" class="btn" value="button"></td>

</tr>

<tr>

<td val="2">111</td><td>6666</td><td><input type="button" class="btn" value="button"></td>

</tr>

</table>

</body>

</html>