I'm trying to add a table using jQuery's appendTo
function whenever a certain button is clicked. Here's my code:
我试图在点击某个按钮时使用jQuery的appendTo函数添加一个表。这是我的代码:
$("#button").click(function() {
$("#divId").dialog("open");
$('#divId').appendTo('.table_width');
});
Note that in this code, .table_width
is the table class and #divId
is the div identity. However, this does not seem to be working. Am I doing this the right way? Thanks in advance for any help.
请注意,在此代码中,.table_width是表类,#diviv是div标识。但是,这似乎不起作用。我这样做是对的吗?在此先感谢您的帮助。
3 个解决方案
#1
1
Use .append
instead of .appendTo
. What I understand from your question is that you want to append an existing table to #divId..appendTo
will append your div to the table, which is not what you want.
使用.append而不是.appendTo。我从你的问题中理解的是你想要将现有的表附加到#divId..appendTo会将你的div附加到表中,这不是你想要的。
#2
0
Are you trying to create a whole new table on every click, or just a table row?
您是尝试在每次点击时创建一个全新的表格,还是仅仅是一个表格行?
Anyway, you need to use "add()" to create new elements. To add a new (empty) row to an existing table, use:
无论如何,您需要使用“add()”来创建新元素。要将新(空)行添加到现有表,请使用:
$("#button").click(function() {
$('#existing_table').add('tr').addClass('.table_width');
});
This will append a new row with the "table_width" class. Not sure if that's what you want though ;)
这将使用“table_width”类附加一个新行。不确定这是否是你想要的;)
#3
0
Something like this:
像这样的东西:
$("#button").click(function() {
$('#divId').append($('.table_width')).dialog("open");
});
#1
1
Use .append
instead of .appendTo
. What I understand from your question is that you want to append an existing table to #divId..appendTo
will append your div to the table, which is not what you want.
使用.append而不是.appendTo。我从你的问题中理解的是你想要将现有的表附加到#divId..appendTo会将你的div附加到表中,这不是你想要的。
#2
0
Are you trying to create a whole new table on every click, or just a table row?
您是尝试在每次点击时创建一个全新的表格,还是仅仅是一个表格行?
Anyway, you need to use "add()" to create new elements. To add a new (empty) row to an existing table, use:
无论如何,您需要使用“add()”来创建新元素。要将新(空)行添加到现有表,请使用:
$("#button").click(function() {
$('#existing_table').add('tr').addClass('.table_width');
});
This will append a new row with the "table_width" class. Not sure if that's what you want though ;)
这将使用“table_width”类附加一个新行。不确定这是否是你想要的;)
#3
0
Something like this:
像这样的东西:
$("#button").click(function() {
$('#divId').append($('.table_width')).dialog("open");
});