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>