Home > front end >  Check for code example of the same word with a text box and into a red
Check for code example of the same word with a text box and into a red

Time:10-04

Do really use,
The original code is like this:
The function highlight (text)
{

InputText=document. GetElementById (" inputText ")
Var innerHTML=inputText. InnerHTML
Var index=innerHTML. IndexOf (text);
If (index & gt;=0)
{
InnerHTML=innerHTML. Substring (0, index) + "& lt; Span class='highlight' & gt;" + innerHTML. Substring (index, the index + text length) + "& lt;/span>" + innerHTML. Substring (index + text. Length);
InputText. InnerHTML=innerHTML
}

}
Highlight (' {1} {word} ');

</script>
Behind the front call no problem, change a ID number to use this doesn't work, don't know where the problem is, for help, thank you,

CodePudding user response:

What change a ID number? Clear, or send the complete code,

CodePudding user response:



<script>

The function highlight (text)
{


InputText=document. GetElementById (" ff ")


Var innerHTML=inputText. InnerHTML
Var index=innerHTML. IndexOf (text);

If (index & gt;=0)
{
InnerHTML=innerHTML. Substring (0, index) + "& lt; Span class='highlight' & gt;" + innerHTML. Substring (index, the index + text length) + "& lt;/span>" + innerHTML. Substring (index + text. Length);
InputText. InnerHTML=innerHTML
}

}
Highlight (' {{word2}} ')
</script>

CodePudding user response:

Behind for the first time with no problem, so the same code, not work

{{sentences}} & lt; Span & gt;



<script>

The function highlight (text)
{

InputText=document. GetElementById (" inputText ")
Var innerHTML=inputText. InnerHTML
Var index=innerHTML. IndexOf (text);
If (index & gt;=0)
{
InnerHTML=innerHTML. Substring (0, index) + "& lt; Span class='highlight' & gt;" + innerHTML. Substring (index, the index + text length) + "& lt;/span>" + innerHTML. Substring (index + text. Length);
InputText. InnerHTML=innerHTML
}

}
Highlight (' {1} {word} ');

</script>

CodePudding user response:

Normal
 


<meta charset="utf-8"/& gt;
<meta HTTP - equiv="X - UA - Compatible" content="IE=edge, chrome=1"/& gt;

<style type="text/CSS" & gt;
. Highlight {
Color: red;
}
</style>

<body>

<script>
The function highlight (text)
{
Var inputText=document. GetElementById (" ff ");
Var innerHTML=inputText. InnerHTML;
Var index=innerHTML. IndexOf (text);
If (index & gt;=0)
{
InnerHTML=innerHTML. Substring (0, index) + "& lt; Span class='highlight' & gt;" + innerHTML. Substring (index, the index + text length) + "& lt;/span>" + innerHTML. Substring (index + text. Length);
InputText. InnerHTML=innerHTML;
}
}
Highlight (' ABC ');
</script>


CodePudding user response:

First with no problem, later no reaction

CodePudding user response:

reference 5 floor flayying reply:
1 time with no problem, later again the no reaction

Call again when you add the last of the first span tags deleted
Var innerHTML=inputText. InnerHTML. Replace (" & lt; Span class=\ "highlight " & gt;" , ""). The replace (" & lt;/span>" , "");

CodePudding user response:

Behind the callback is the other way, you write the complete have no reaction

CodePudding user response:

CodePudding user response:

Before a normal, behind the example, how have no reaction, the same code

CodePudding user response:

references 9 f flayying response:
before a normal, behind the example, how have no reaction, the same code

You are a defines two highlight () function? Function name repetition of course not,
The id passed to functions, parameters with a function,
 


<meta charset="utf-8"/& gt;
<meta HTTP - equiv="X - UA - Compatible" content="IE=edge, chrome=1"/& gt;

<style type="text/CSS" & gt;
. Highlight {
Color: red;
}
</style>

<body>


<script>
The function highlight (text, id)
{
Var inputText=document. GetElementById (id);
Var innerHTML=inputText. InnerHTML;
Var index=innerHTML. IndexOf (text);
If (index & gt;=0)
{
InnerHTML=innerHTML. Substring (0, index) + "& lt; Span class='highlight' & gt;" + innerHTML. Substring (index, the index + text length) + "& lt;/span>" + innerHTML. Substring (index + text. Length);
InputText. InnerHTML=innerHTML;
}
}
Highlight (' ABC ', "ff");
Highlight (' 567 ', "ee"); nullnullnullnullnullnullnull
  • Related