jquery 只能添加结束元素标签(标记)吗? [英] Can jquery add closing element tags (markup) only?

查看:27
本文介绍了jquery 只能添加结束元素标签(标记)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定表中的第n行,jquery是否可以只添加关闭表的标记

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>             --

我正在尝试使用:

$('tr.eop').append("</tbody></table><table>+head+<tbody>");   // head = table header

推荐答案

DOM 由元素节点组成,一旦元素成为 DOM 或 DOM Fragment 的一部分,开始和结束标记就没有任何意义.

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屋!

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