gpt4 book ai didi

javascript - Jquery:从字符串中获取标题和正文标签内容

转载 作者:行者123 更新时间:2023-11-28 05:01:47 24 4
gpt4 key购买 nike

我有一个如下所示的字符串:

<head>
This is the Head
</head>
<body>
<div>
<div>
<p> Body Content <br /></p>
<p>&nbsp; Hello World <br /></p>
</div>
</div>
</body>

它有 head 和 body 标签。现在我想要使用 jquery 获取 head 标签和 body 标签的内容。有人可以帮忙吗?

最佳答案

假设您的字符串变量是“s”,那么代码是:

var html = document.createElement('html');
html.innerHTML = s;

var head = $(html).find('head:first');
var body = $(html).find('body:first');

关于javascript - Jquery:从字符串中获取标题和正文标签内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42089024/

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