Template content: please go to the meeting @} {XXXX, I want to put @} {XXXX replace input label, how to write
CodePudding user response:
CodePudding user response:
For example
TMP=", "please go to the meeting @} {XXXX. //val=document. GetElementById (" your_input_tag_id ") [0]. Value;//get the value from the input Val="input tag"; TMP TMP.=replace (/[@] [{]. *?/[}], val); The console. The log (TMP); CodePudding user response:
reference 1st floor qq_63572063 response: thank you bosses! I have a question is how to change the teacher asked This is my replacement code: var modelContent=optionObj. ModelContent; Var content=modelContent. Replace (/@ \ {(. *?) }/g, "& lt; Input type=\ "+ " text placeholder=\ "@ {message} " & gt; " ); $(" # form "). Append (content); CodePudding user response:
Is not open to stick and solve problems and posted? How to open a the same??????? Not understand what do you mean by the so-called specific to the requirements of a teacher, are reserved to the information other than the match or not?? A: keep matches outside information The function replace2Tmpl (STR: string) { Return the STR. Replace (/@ \ {(. *?) \}/g (m, I)=& gt; { /* * * according to the following instructions self-assembly to return to the content of the * m=& gt; @} {XXX; I=& gt; XXX */ //do you //return '& lt; Input type="text" placeholder="' + m + '" & gt; ' //the teacher asked Return the m + '& lt; Input type="text" id="' + I +" & gt; ' }) }; Const TMPL=replace2Tmpl (' system in @ {message1} maintenance @ {message2} please do backup '); The console. The log (TMPL); 2: remove the outside match information The function replace2Tmpl2 (STR: string) { Const arr=STR. Match (/@ \ {(. *?) \}/g); Return arr ? Arr. Join ("). The replace (/@ \ {(. *?) \}/g (m, I)=& gt; { /* * * according to the following instructions self-assembly to return to the content of the * m=& gt; @} {XXX; I=& gt; XXX */ //do you //return '& lt; Input type="text" placeholder="' + m + '" & gt; ' //the teacher asked Return the m + '& lt; Input type="text" id="' + I +" & gt; ' }) : STR;//if a match is not found, the original string }; Const TMPL=replace2Tmpl2 (' system in @ {message1} maintenance @ {message2} please do backup '); The console. The log (TMPL);