私はJavaScriptが初めてです。これは私のコードのフィドルです。
削除するCDATA
と、フィドルでは問題なく動作しますが、Eclipse などの XHTML エディターでは問題が発生します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
これは私のJavaScriptです:
<![CDATA[
function test() {
alert(document.getElementById("divId"));
var regex = new RegExp('this',"gi");
document.getElementById("divId").innerHTML
= document.getElementById("divId").innerHTML.replace(regex,
function(matched)
{
return '<span class=\'highlight\'>' + matched + '</span>';
});
}
]]>
ここ<div>
に問題があります:
<div id="divId">
This is the text This is the text This is the text This is the text
This is the text This is the text This is the the text
</div>
関数を呼び出すことができませんtest()
。助言がありますか?