gpt4 book ai didi

jQuery 从字符串中选择 body 元素

转载 作者:行者123 更新时间:2023-12-03 22:58:58 25 4
gpt4 key购买 nike

我有一个字符串<html><head></head><body>test</body></html>我正在尝试使用 jQuery 获取正文的内容。

我试过了

$('<html><head></head><body>test</body></html>').find('body').html();

但这不起作用。

关于如何做到这一点有什么想法吗?

编辑:

如果不清楚,我需要从字符串获取 body 元素,而不是 DOM。

编辑2:

请注意,所使用的方法不需要从head返回任何内容。元素。例如内联样式。

最佳答案

var x = '<html><head></head><body>test</body></html>';
x = x.split("<body")[1].split(">").slice(1).join(">").split("</body>")[0];
alert(x);

检查工作示例 http://jsfiddle.net/6hPHn/1/

关于jQuery 从字符串中选择 body 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574220/

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