作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个字符串<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);
关于jQuery 从字符串中选择 body 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574220/
我是一名优秀的程序员,十分优秀!