日期:2014-05-16 浏览次数:20504 次
<!DOCTYPE html>
<html>
<head>
<title>Duplicate Cell</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//数据
var data =
[
{ No: "1", Name: "Jeffrey", Date: "2011/05/07", Score: 2011 },
{ No: "1", Name: "Jeffrey", Date: "2011/06/21", Score: 9999 },
{ No: "1", Name: "Jeffrey", Date: "2011/06/22", Score: 32767 },
{ No: "2", Name: "Mulder", Date: "2011/06/01", Score: 999 },
{ No: "3", Name: "Darkthread", Date: "2011/06/10", Score: 100 },
{ No: "3", Name: "Darkthread", Date: "2011/06/15", Score: 100 }
];
var h = [];
for (var i = 0; i < data.length; i++) {
h.push("<tr>");
var obj = data[i];
for (var p in obj)
h.push("<td>" + obj[p] + "</td>");
h.push("</tr>");
}
$("#scoreboard tbody").html(h.join('\n'));
$("#btnShowMe").click(function () {
//在此添加代码
})
});
</script>
<style type="text/css">
#scoreboard { width: 400px; margin-top: 20px; }
#scoreboard td { border: 1px solid gray; padding: 4px; }
#scoreboard thead { text-align: center; background-color: #ddd; }
#scoreboard tbody { text-align: center; }
td.c-Score { text-align: right; }
</style>
</head>
<body>
<input type="button" id="btnShowMe" value="test" />
<table id="scoreboard">
<thead>
<tr><td>No</td><td>Name</td><td>Date</td><td>Score</td></tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
$("#btnShowMe").click(function () {
//在此添加代码
$('#scoreboard tbody tr').each(function(){
alert( $(this).find('td:eq(1)').html() )
})
})
------解决方案--------------------
$("#btnShowMe").click(function () {
alert($(data).map(function () { return this.Name }).get().join());//直接操作数据
alert($('tbody tr td:nth-child(2)').map(function () { return this.innerHTML }).get().join());//操作DOM对象
})
------解决方案--------------------
再来种一方法~
$("#btnShowMe").click(function () {
//在此添加代码
$('#scoreboard tbody tr td').each(function(i){
if(i%4==1){
alert($(this).text());
}
})
})
------解决方案--------------------
$("#btnShowMe").click(function () {
alert( $('#scoreboard tbody tr td:eq(1)').length ) // 1
})
并非 td:eq(1) 的 arrayList