我是JavaScript新手。 This is a fiddle与我的代码。无法呼叫测试()
如果我删除CDATA
那么它适用于小提琴正常,但在XHTML编辑器创建问题,如Eclipse:
<!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()
功能。有什么建议么?
什么是 “无法” 是什么意思?你有错误吗?你是怎么称呼它的? – Zim84
我的建议?停止使用xHTML(特别是Transitional)并切换到HTML5。对于初学者,您不需要丑陋的CDATA评论符号。 ;) –
由无法我的意思functio不是calls.i没有发现任何错误 – viki