2013-07-03 4 views
2

여기에 실행 코드가 fiddle
입니다. 완벽하게 잘 작동하는 것을 볼 수 있습니다. 그러나이 코드를 glassfish 서버 3.2.1을 사용하여 Eclipse에서 실행하면 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". 


는 나뿐만 아니라 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> 

을 그것을 시도 XHTML 페이지 (정확히 같은 같은 바이올린)의 코드..

답변

2

아마도 XHTML이 잘못되었습니다.

CDATA 섹션에 자바 스크립트 코드를 입력하십시오.

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

CData 섹션? 당신은 정교하게 부탁합니다 – viki

+0

@viki 예제를 추가하십시오. 자세한 내용은 링크를 참조하십시오. – Uooo

+0

CData가 오류를 제거했지만 이제는'test()'함수가 – viki

관련 문제