2013-07-03 3 views
2

Пробег код fiddle
Вы увидите, что он отлично работает здесь, но когда я запускаю этот код в eclipse, используя сервер Glassfish 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

Смежные вопросы