简体   繁体   English

使用javascript获取第二个正文

[英]Get second body text using javascript

Basically HTML elements contain a body tag. 基本上,HTML元素包含一个body标签。 In this body tag we add required html content. 在此正文标签中,我们添加了必需的html内容。 In my cases HTML file has two body content one for whole html content as usual another one for Rich Text Editor. 在我的情况下,HTML文件具有两个正文内容,一个通常用于整个html内容,另一个则用于Rich Text Editor。 I need to take Rich Text Editor text using second body. 我需要使用第二个正文获取Rich Text Editor文本。

I have already tried as follows get body tag value from website Get all elements in the body tag using pure javascript 我已经尝试了以下方法, 从网站 获取 body标签值: 使用纯javascript 获取body标签中的 所有元素

second body html content as follow, 第二个正文的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>

I also tried with class name as follows but shows $(...).text is not a function. 我还尝试使用类名称,如下所示,但显示$(...)。text不是函数。

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

Please give your suggestions.. Thanks 请提出您的建议。。谢谢

Try to add jquery library or use javascript 尝试添加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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM