gabesoftの答えのコメントで参照されているcontenteditableプロパティを処理する簡単なjavascriptの例です。単語のリストを定義し、テキストボックスを指定して、ハイライトを行うためにボタンを使用することができます。
JSFiddle Example
HTML:
<p contenteditable="true">This is a test of the word highlight system.</p>
<button onClick="highlightWords()">highlight</button>
JS:
//define words you want highlighted
var arr = ['test', 'system'];
//locate the element on the page to do the word operations
//this will find the first <p> tag
var textbox = document.getElementsByTagName('p')[0];
var highlightWords = function() {
//foreach word, perform highlighting actions
arr.forEach(function(word) {
//build regular expression to match against each variable (word) in our list
var regex = new RegExp("(" + word + ")", "gi");
//g = can find multiple instances (global)
//i = case insenstive
//replace predefined textbox HTML with 'highlighted' version
//the regex will find matching words and wrap them in <strong> tags
//the $1 represents the matched word
textbox.innerHTML = textbox.innerHTML.replace(regex, "<strong>$1</strong>");
});
}
うん、言葉が変化しているものは何でも識別私と罰金です。私は主に、その単語を識別してその言葉に変更を加える方法を理解する必要があります。大文字、斜体、帽子などに変えてください。 –
ああ、テキストボックスの値の中にマークアップを付けることができないので、テキストボックス内で単語を個別にスタイルすることはできません。あなたは '' contenteditable''プロパティを設定することによって編集可能なdivを使うことができます – gabesoft
このペンを見てくださいhttp://codepen.io/anon/pen/ZWJzOV – gabesoft