gpt4 book ai didi

javascript - 使用 javascript 获取第二个正文文本

转载 作者:行者123 更新时间:2023-12-03 03:23:30 26 4
gpt4 key购买 nike

基本上 HTML 元素包含一个 body 标签。在此 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>

我还尝试使用类名,如下所示,但显示 $(...).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>

关于javascript - 使用 javascript 获取第二个正文文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461969/

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