2013-07-03 68 views
2

这是fiddle
上的运行代码你会看到它在这里工作得很好,但是当我在eclipse中使用glassfish server 3.2.1在xhtml页面中运行此代码时,它会给出这个错误
javascript代码不工作在JSF xhtml页

javax.servlet.ServletException: Error Parsing /MasterPage/MiDASMaster.xhtml: Error Traced[line: 135] Open quote is expected for attribute "{1}" associated with an element type "class". 


这是XHTML页面(完全相同像小提琴)的代码,我试了一下Jsbin以及

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

<html> 
<head> 
<style type="text/css"> 
.highlight { 
    background:yellow; 
} 
.removeHighlight { 
    background:green; 
} 

</style> 
<script type="text/javascript" src="../Scripts/jquery-1.8.3.js"/> 
</head> 
<body> 

<script type="text/javascript"> 

      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>'; 
     }); 


    } 



</script> 

<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> 

..

回答

2

您的XHTML格式可能不正确。

将您的Javascript代码插入CDATA部分。

<script type="text/javascript"> 
    <![CDATA[ 
     alert("Your javascript here"); 
    ]]> 
</script> 
+0

CData部分?你能否详细说明 – viki

+0

@viki补充的例子。欲了解更多信息,请访问链接。 – Uooo

+0

CData已经删除了错误,但现在函数'test()'不会调用 – viki