Home > front end >  For help how will return to the back-end for a period of all the p in the HTML tag to remove leading
For help how will return to the back-end for a period of all the p in the HTML tag to remove leading

Time:02-26


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 relpace
For 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:

reference qybao reply: 3/f
extract each & lt; P> Elements (getElementsByTagName), then use a regular relpace
For 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;
}

Val=val. Replace (/^ \ s +/");//at the beginning of space
Val=val. Replace (/\ s + $/, ");//at the end of the space
This orthography why not directly use the trim

CodePudding user response:

my sensitivity to the fairy reference 4 floor response:
val=val. Replace (/^ \ s +/");//at the beginning of space
Val=val. Replace (/\ s + $/, ");//at the end of the space
This orthography why not directly use the trim

This is told to make another approach, needs to want to removes white Spaces at the beginning of one thousand, or just want to get rid of at the end of the blank space?
So much to know a way isn't a bad thing,
  • Related