简体   繁体   English

将多行文字与元素分开

[英]Separate multi-line text from an element

I have an element that looks like this in the Developer Console: 我在开发人员控制台中有一个看起来像这样的元素:

<span>
  "Total Items: "
  "10"
</span>

I want to get only the second string (the "10") out of it, but textContent , innerText , outerText , innerHTML and outerHTML all concatenate the value into a single string (with no newline). 我想只有第二个字符串(“10”)出来的,但textContentinnerTextouterTextinnerHTMLouterHTML所有串联的值转换成一个字符串(不换行)。

How can I detect where the split was in the original HTML? 如何检测原始HTML中的拆分位置?

I'm using Javascript (Node.js), so a JQuery or Cheerio solution would work for me. 我正在使用Javascript(Node.js),因此可以使用JQuery或Cheerio解决方案。

Well it depends what breaks are you using, but try selecting the inner html and spliting it on the break itself 好吧,这取决于您使用的是哪种休息时间,但是请尝试选择内部html并将其在休息时间本身上拆分

var splitString = $("span")[0].innerHTML.split("\n")
var secondLine = splitString[1]

If you don't have any newline you could use a RegEx for splitting: 如果没有任何换行符,则可以使用RegEx进行拆分:

myString.split(/"(.*?)"/g)

And then get the second value. 然后获得第二个值。

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

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