gpt4 book ai didi

jquery - 使用 jquery 将 html 表转换为字符串

转载 作者:行者123 更新时间:2023-11-27 22:32:17 27 4
gpt4 key购买 nike

<分区>

我在一个字符串中有一些 html,我需要从中提取一个表格。因此,例如,我的 htmlString 变量包含 (:

<html><head>....some head stuff</head><body><table>.... some table stuff</table>.... other body stuff</body></html>

所以,我尝试过的是:(打出来的,不是复制的,所以可能有错别字)

var table = $( '' ).append( htmlString ).find( 'table' ).get();

如果我查看我的表变量,我会看到:

[<table>...</table>]

所以,我相信我正确地从 html 字符串中提取了表格。

现在,要将其转换回字符串,我执行以下操作:

var tableString = $( table[0] ).html();

然后我回来了:

<tbody> ... the table stuff ... </tbody>

但是,我想要的是:

<table> ... the table stuff ... </table>

我该怎么做?

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