JQuery在表格末尾添加数据 [英] JQuery Append Data at end of table

查看:116
本文介绍了JQuery在表格末尾添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < table id =myTable0name =myTable0> 
< tbody>
< tr>
< / tr>
< / tbody>
< / table>

< table id =myTable1name =myTable1>
< tbody>
< tr>
< / tr>
< / tbody>
< / table>

我需要一些JQuery,它会尝试将新的html附加到表的末尾并在其上执行输入键,它也会选择正确的表格来追加它,因为有很多表格。



这是我的代码,但不能正常工作,但是试图做到这一点:
$ b $ pre $ for(i = 0; i <2; i ++)
{
$(# newComment+ i).keyup(function(event){
if(event.keyCode == 13){
var $ test = $('< tr>< td> content here< td>< / tr>');
$('#myTable'+ i +'> tbody:last')。append($ test);
}
}

引发我问题的线是以下的Jquery select:

  $('#myTable'+ i +'> tbody:last')。append($ newdiv1); 

 

解决方案

code> $('#myTable'+ i +'> tbody:last')。append($ newdiv1);

空格 $('#myTable' ..



您在#myTable和0之间有空格。

您需要#myTable0 当你有 #myTable 0


<table id="myTable0" name="myTable0">
<tbody>
<tr>
</tr>
</tbody>
</table>

<table id="myTable1" name="myTable1">
<tbody>
<tr>
</tr>
</tbody>
</table>

I need some JQuery that will attempt to append new html to the end of a table and do it on the enter key, it will also select the correct table to append it to as there are numerous tables.

Here is my code that doesn't work but attempts to do this:

for (i=0; i<2; i++)
  {
$("#newComment" + i).keyup(function(event){
    if(event.keyCode == 13){
        var $test= $('<tr><td>content here</td></tr>');
        $('#myTable '+ i + ' > tbody:last').append($test);
    }
}

The line that is throwing me problems is the Jquery select which follows:

$('#myTable '+ i + ' > tbody:last').append($newdiv1);

解决方案

Try this:

$('#myTable' + i + ' > tbody:last').append($newdiv1);

The space $('#myTable ' is the problem..

You are having space between #myTable and 0..

You need #myTable0 while you were having #myTable 0

这篇关于JQuery在表格末尾添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆