简体   繁体   English

如何在删除换行符时将HTML文本转换为Javascript变量?

[英]How Do I Turn HTML Text into a Javascript Variable While Removing Line Breaks?

I have a raw feed of some text within the body tag of an HTML page. 我在HTML页面的body标签内有一些文本的原始提要。 I need to run a function on it to turn it into a Javascript string variable. 我需要对其运行一个函数,以将其转换为Javascript字符串变量。 However, there are literal line breaks in the HTML page (which are obviously not permissible in JS strings). 但是,HTML页面中存在文字换行符(显然在JS字符串中是不允许的)。

Here's an example of the source of the page I'm working with: 这是我正在使用的页面来源的示例:

<html>
<head></head>
<body>
BLDG||0|EOR|

PLNC||0|EOR|

SUBD|Pine Manor|1|EOR|

CITY|Fort Myers|1|EOR|

</body>

jQuery is permissible. jQuery是允许的。 How do I turn this all into a Javascript variable while removing the literal line breaks so that the variables work? 如何在删除文字换行符的同时将其全部转换为Javascript变量,以便变量起作用?

var str = document.body.innerHTML.replace(/(\r\n|\n|\r)/gm,"");

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

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