javascript - Detecting line-breaks in browser/css-forced line breaks -
& lt; P style = "width: 60px" & gt; I am some random text. I have some text. Blubber & lt; / P & gt;
The translated HTML may have the above result,
I have some RDO text. I have some text. Bblabla
I want to split the paragraph line from the above paragraph lines. So what is the expected result,
& lt; P style = "width: 60px" & gt; I have some RA & lt; / P & gt; & Lt; P style = "width: 60px" & gt; Nandom Text I & lt; / P & gt; & Lt; P style = "width: 60px" & gt; Some text & lt; / P & gt; & Lt; P style = "width: 60px" & gt; .blabla & lt; / P & gt;
Is it possible to apply in JavaScript?
Why do I divide it by PS? Because I would like to get my paging system for a long HTML, where all the paragraphs and splag paragraphs within one height are the same & lt; Div class = "page" & gt; & Lt; / Div & gt;
. Finally, the entire HTML should be
& lt; Div id = "page1" class = "page" & gt; Will be arranged as. & Lt; P & gt; Full content & lt; / P & gt; & Lt; P & gt; Top of XXX & lt; / P & gt; & Lt; / Div & gt; & Lt; Div id = "page2" class = "page" & gt; & Lt; P & gt; Bottom of XXX & lt; / P & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; / Div & gt;
Well, let's say your text is a & lt; P id = 'full text' & gt;
:
var element = document.getElementById ("full text"); Var full text = element.inner html; Var split text = whole text Split ("\ r \ n"); Var newHtml = null; (Var i = 0; i & lt; splittext.length; i ++) {newHtml + = "& lt; p class = 'each-line'> + Splittext [i] + '& lt; / P & gt; '; }
You can then use newHtml
to type in a DOM element. For example, if you do this same & lt; P & gt;
, from which you received the text, you do it:
element.innerHTML = newHtml; // Element element element & lt; P & gt;
with the full text ID, insert all the codes in one function and call the function after the window is fully loaded.
Window AddEvenetListener ("Load", function () {// put code here}, false);
If your line does not have a breaking letter
, please refer to this plugin:
The above link suggested in this SO question Gone:
Comments
Post a Comment