The content="
(hey! HuoErMa, what's your plan?
It is on the trot, but barely keep pace with short legs than himself, and walking or state girl, an incredible, & lt;/p>
(...... No, no, no,) & lt;/p>
(hey! HuoErMa, what's your plan?
XXX xxx
"
If inscribe
Content field returns the contents as shown in the above possible & lt; P> And & lt; P style="XXX" & gt;
How regular or javascript to remove the content in the label of every p, leading and trailing Spaces, and keep the p tag space among
CodePudding user response:
Var div=document. The createElement method (' div ');
Div. InnerHTML=` & lt; P> (hey! HuoErMa, what's your plan?It is on the trot, but barely keep pace with short legs than himself, and walking or state girl, an incredible, & lt;/p>
(...... No, no, no,) & lt;/p>
(hey! HuoErMa, what's your plan?
XXX xxx
`;
Var pList=div. GetElementsByTagName (" p ");
The console. The log (pList [0]. The innerText);
CodePudding user response:
The above with a loop and trim can
Var div=document. The createElement method (' div ');
Div. InnerHTML=` & lt; P> (hey! HuoErMa, what's your plan?It is on the trot, but barely keep pace with short legs than himself, and walking or state girl, an incredible, & lt;/p>
(...... No, no, no,) & lt;/p>
(hey! HuoErMa, what's your plan?
XXX xxx
`;
Var pList=div. GetElementsByTagName (" p ");
For (var I=0, n=pList. Length; IThe console. The log (pList [I] the innerText. The trim ());
}
CodePudding user response:
Extract each & lt; P> Elements (getElementsByTagName), then use a regular relpaceFor example
var tag;
Var val.
For (the tag in the document. The getElementsByTagName (" p ")) {
Val=tag. InnerHtml;
Val=val. Replace (/^ \ s +/");//at the beginning of space
Val=val. Replace (/\ s + $/, ");//at the end of the space
The tag. The innerHtml=val;
}
CodePudding user response: