我是 Javascript 新手。我有一个问题:如何突出显示文本中输入的单词。我只能做检查这个词是否在文本中的部分,但无法在文本中突出显示这个词。提前谢谢大家!
var paragraph = document.getElementById('paragraph').innerText; //PARAGRAPH
input = document.getElementById('typed-text').value; //TYPED TEXT
textIncludes = paragraph.includes(input); // TEXT INCLUDES WORD
if (textIncludes === true) {
alert('Word has been found')
} else {
alert('No matches found')
}Run Code Online (Sandbox Code Playgroud)
<div id="highlights">
<div class="container">
<div class="row">
<div class="col-md-12" id="paragraph">
<p>
Robotics is an interdisciplinary branch of engineering and science that includes mechanical engineering, electronics engineering, information engineering, computer science, and others. Robotics deals with the design, construction, operation, and use of robots, as well …Run Code Online (Sandbox Code Playgroud)