我想要获得每行第一列的值href单击编辑。例如,如果我点击第一行href,那么我应该得到第一列值的警报。我想获得第一列行的值在eack href中单击HTML表
$(document).ready(function() {
var jsonData = [{
id: 'A01',
name: 'Fadhly'
}, {
id: 'A02',
name: 'Permata'
}, {
id: 'A03',
name: 'Haura'
}, {
id: 'A04',
name: 'Aira'
}];
$.each(jsonData, function (key, val) {
var tr = '<tr>';
tr += '<td>' + (key + 1) + '</td>';
tr += '<td>' + val.id + '</td>';
tr += '<td>' + val.name + '</td>';
tr += '<td><a href="#menu1">Edit</a</td>';
tr += '</tr>';
$('tbody').append(tr);
});
我的HTML代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1" width="100%">
<thead>
<tr>
<th>#</th>
<th>Id</th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
在上表中,如果我点击第一行编辑href,那么它应该在alert框中打印id。我不想在按钮上点击只有href点击。 –
这不是[JSON](http://www.json.org/) - > [JSON和Object Literal Notation之间的区别是什么?](https://stackoverflow.com/questions/2904131/what-is- json-and-object-literal-notation之间的差异) – Andreas
请检查我的更新代码,并请帮助获取每行href单击值。 –