使用 javascript 获取第二个正文

Get second body text using javascript

基本上 HTML 个元素包含 body 标签。在这个正文标签中,我们添加了必需的 html 内容。在我的例子中,HTML 文件有两个正文内容,一个用于整个 html 内容,另一个用于富文本编辑器。我需要使用第二个正文获取富文本编辑器文本。

我已经试过如下 get body tag value from website Get all elements in the body tag using pure javascript

二体html内容如下,

<body marginwidth="0" marginheight="0" spellcheck="true" class="wysihtml5-editor" style="font-variant-ligatures: normal; font-variant-caps: normal; background-color: rgb(255, 255, 255); color: rgb(95, 100, 104); cursor: auto; font-family: &quot;Open Sans&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; line-height: 18px; letter-spacing: normal; text-align: start; text-decoration: none solid rgb(95, 100, 104); text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word; word-spacing: 0px;" contenteditable="true">testing</body>

我也尝试使用 class name 如下,但显示 $(...).text 不是函数。

$(".wysihtml5-editor").text()

请提出您的建议.. 谢谢

尝试添加 jquery 库或使用 javascript

//by javascript
var text = document.getElementsByTagName("body")[0].textContent
alert(text);

//by jquery
$(document).ready(function(){
    var text = $('body').text();
    alert(text);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body marginwidth="0" marginheight="0" spellcheck="true" class="wysihtml5-editor" style="font-variant-ligatures: normal; font-variant-caps: normal; background-color: rgb(255, 255, 255); color: rgb(95, 100, 104); cursor: auto; font-family: &quot;Open Sans&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; line-height: 18px; letter-spacing: normal; text-align: start; text-decoration: none solid rgb(95, 100, 104); text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word; word-spacing: 0px;" contenteditable="true">testing</body>