可以jQuery的只添加结束元素标记(标记)? [英] Can jquery add closing element tags (markup) only?
问题描述
鉴于这种第n行中的一个表,可以JQUERY仅添加标记以关闭表
< TR类=EOP>
&所述; TD> 8/31< / TD>
&所述; TD> XYZ< / TD>
&所述; TD> 2'; / TD>
&所述; TD> 92.00< / TD>
< / TR> < / TBODY> -
< /表> |
<表> - //插入标记
头jQuery的VAR |
<&TBODY GT; -
我想要是使用:
$('tr.eop')追加(< / TBODY>< /表><表> +头+< TBODY>); //头=表头
的DOM元素组成的节点,在开始和结束标记意味着什么,一旦一个元素是DOM或DOM片段的一部分。
您不能附加元素没有关闭标签页。如果省略结束标记,一会为您创建。您也不能通过附加结束标记作为一个孩子关闭父元素,这反而简单地创建父元素中一个新的完整的元素。
如果你想创建一个新表,创建新表。
VAR newtable的= $(<表>< THEAD>中+头+< / THEAD>< TBODY>< / TBODY>< /表> );
$('tr.eop')。最近(表)。后(newtable中)
。$('tr.eop')nextAll()appendTo(newTable.find(TBODY));
Given this nth row in a table, can jquery add only the markup to close the table
<tr class="eop">
<td> 8/31 </td>
<td> XYZ </td>
<td> 2 </td>
<td> 92.00 </td>
</tr>
</tbody> --
</table> |
<table> -- // inserted markup
head jquery var |
<tbody> --
What I'm trying is to use:
$('tr.eop').append("</tbody></table><table>+head+<tbody>"); // head = table header
The DOM consists of element nodes, the opening and closing tags mean nothing once an element is part of the DOM or a DOM Fragment.
You cannot attach elements to the page that do not have a closing tag. If the closing tag is omitted, one will be created for you. You also cannot close a parent element by appending a closing tag as a child, it will instead simply create a new complete element inside the parent element.
If you want to create a new table, create a new table.
var newTable = $("<table><thead>"+head+"</thead><tbody></tbody></table>");
$('tr.eop').closest("table").after(newTable)
$('tr.eop').nextAll().appendTo(newTable.find("tbody"));
这篇关于可以jQuery的只添加结束元素标记(标记)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!