怎么把这段数据输出

y362623206 2015-06-12 04:20:23
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tbody>
<tr>
<td class="b"></td>
<td class="c"></td>
</tr>
<tr>
<td class="b"></td>
<td class="c"></td>
</tr>
</tbody>
</table>
</body>
</html>

var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}],

第一个tr输出2,3 第二个tr输出5,6
...全文
125 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqw6789567 2015-06-12
  • 打赏
  • 举报
回复
<html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tbody> <tr> <td class="b"></td> <td class="c"></td> </tr> <tr> <td class="b"></td> <td class="c"></td> </tr> </tbody> </table> <script type="text/javascript"> var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}]; $("tr").each(function (i){ $("td",this).each(function (){ $(this).text(data[i][this.className]); }) }); </script> </body> </html> 这个正解
y362623206 2015-06-12
  • 打赏
  • 举报
回复
引用 3 楼 jslang 的回复:
6 [quote=引用 2 楼 u012153496 的回复:] [quote=引用 1 楼 jslang 的回复:]

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>

 <table>
    <tbody>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
    </tbody>
 </table>
<script type="text/javascript">
var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}];
$("tr").each(function (i){
	$("td",this).each(function (){
		$(this).text(data[i][this.className]);
	})
});
</script>
 </body>
</html>

为什么我应用后报Uncaught TypeError: Cannot read property '' of undefined这个错误[/quote] 那可能是tr元素的数量多于data数组元素的数量[/quote] 是有个表头的原因 已经好了 谢谢了
天际的海浪 2015-06-12
  • 打赏
  • 举报
回复
6
引用 2 楼 u012153496 的回复:
[quote=引用 1 楼 jslang 的回复:]

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>

 <table>
    <tbody>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
    </tbody>
 </table>
<script type="text/javascript">
var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}];
$("tr").each(function (i){
	$("td",this).each(function (){
		$(this).text(data[i][this.className]);
	})
});
</script>
 </body>
</html>

为什么我应用后报Uncaught TypeError: Cannot read property '' of undefined这个错误[/quote] 那可能是tr元素的数量多于data数组元素的数量
y362623206 2015-06-12
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>

 <table>
    <tbody>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
    </tbody>
 </table>
<script type="text/javascript">
var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}];
$("tr").each(function (i){
	$("td",this).each(function (){
		$(this).text(data[i][this.className]);
	})
});
</script>
 </body>
</html>

为什么我应用后报Uncaught TypeError: Cannot read property '' of undefined这个错误
天际的海浪 2015-06-12
  • 打赏
  • 举报
回复

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>

 <table>
    <tbody>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
        <tr>
            <td class="b"></td>
            <td class="c"></td>
        </tr>
    </tbody>
 </table>
<script type="text/javascript">
var data = [{"a":"1","b":"2","c":"3"},{"a":"4","b":"5","c":"6"}];
$("tr").each(function (i){
	$("td",this).each(function (){
		$(this).text(data[i][this.className]);
	})
});
</script>
 </body>
</html>

87,914

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧