日期:2014-05-16 浏览次数:20313 次
<script src="jquery-1.4.2.js" type="text/javascript" ></script> <table border="1" id="tb1" ><tr><td id="d0"> </td></tr> <tr><td id="d1"> </td></tr> <tr><td id="d2"> </td></tr> <tr><td id="d3"> </td></tr> </table> <script> var arrays=["10:20","11:20","13:32","15:32"]; $(document).ready(function(){ $("#tb1 tr").each(function(i){ $("#d"+i).text(arrays[i]); }); }); </script>
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Untitled</title> <script language="javascript" src="C:\Documents and Settings\wangguanquan\My Documents\jquery.js"></script> <style type="text/css"> table{width:400px;border-top:1px solid #ccc;border-left:1px solid #ccc;} table th{height:28px;background:#cdcdcd;border-right:1px solid #fff;} table tr{height:22px;} table tr td{border-right:1px solid #ccc;border-bottom:1px solid #ccc;} </style> </head> <body> <table cellspacing="0" cellpadding="3"> <colgroup> <col style="width:40px;text-align:right;" /> <col style="width:240px;" /> <col style="width:120px;text-align:center;" /> </colgroup> <th>ID</th><th>内容</th><th>时间</th> <tr><td>1</td><td>内容1</td><td> </td></tr> <tr><td>2</td><td>内容2</td><td> </td></tr> <tr><td>3</td><td>内容3</td><td> </td></tr> <tr><td>4</td><td>内容4</td><td> </td></tr> <tr><td>5</td><td>内容5</td><td> </td></tr> </table> <script language="javascript"> $(function(){ var arrays=["10:20","11:20","13:32","15:32"]; var td = $('table tr td:last-child'); $.each(arrays, function(i, n){ td.get(i).innerHTML = n; }); }); </script> </body> </html>
------解决方案--------------------
var i = 0;
$("#tb1 tbody tr").each(function(){
$("#d"+i).val(arrays[i]);
i++;
)