gpt4 book ai didi

html - Dart的DocumentFragment.html()构造函数在解析一段html时会忽略独立的和标签

转载 作者:行者123 更新时间:2023-12-03 03:28:42 24 4
gpt4 key购买 nike

我有以下HTML:

<tr>
<td><!--Component_property:price--></td>
<td><!--Component_property:size--></td>
<td><!--Component_property:total--></td>
</tr>

我稍后打算将其插入表中。假设它包含在字符串 s中。当我这样做时:
var fragment = new DocumentFragment.html(s);
print(fragment.innerHtml);

输出是这样的:
<!--Component_property:price-->
<!--Component_property:size-->
<!--Component_property:total-->

也就是说,所有 <td><tr>标签都被剥离。如果标记在 <table>标记内或与其他任何标记一起发生,则不会发生这种情况,这表明Dart根本不喜欢片段内的代码无效。

有哪些可能的解决方法?

最佳答案

我建议使用dart:html DOM类来构造trtd元素。您可以执行以下操作,例如:

import 'dart:html';

void main() {
var tr = new TableRowElement();
tr.children.addAll([
new TableCellElement()..text = 'x',
new TableCellElement()..text = 'y']);
querySelector('#myTable').children.add(tr);
}

这将构造一个 tr,向其添加几个 td,然后将整个内容附加到 <table>

关于html - Dart的DocumentFragment.html()构造函数在解析一段html时会忽略独立的<tr>和<td>标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20954633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com