无法调用test() [英] Unable to call test()

查看:99
本文介绍了无法调用test()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JavaScript新手。用我的代码这是一个小提琴

I am new to JavaScript. This is a fiddle with my code.

如果我删除 CDATA ,那么它在小提琴上工作正常,但在像eclipse这样的XHTML编辑器上创建问题:

If I remove CDATA then it works fine on fiddle but create issue on XHTML editors like eclipse:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

这是我的JavaScript:

This is my 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> in问题:

<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()功能。有什么建议?

and I am unable to call test() function. Any suggestions?

推荐答案

只需评论CDATA行:

Just comment CDATA lines :

...
// <![CDATA[
...
// ]]>

这篇关于无法调用test()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆