最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript code not working in JSF xhtml page - Stack Overflow

programmeradmin1浏览0评论

Here is the running code on fiddle
You will see that It is working perfectly fine here but when I run this code in eclipse using glassfish server 3.2.1 in a xhtml page then it gives this error

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


Here is the code of xhtml page(exactly same like fiddle) I tried it on Jsbin as well

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    ".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>

..

Here is the running code on fiddle
You will see that It is working perfectly fine here but when I run this code in eclipse using glassfish server 3.2.1 in a xhtml page then it gives this error

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


Here is the code of xhtml page(exactly same like fiddle) I tried it on Jsbin as well

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3/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>

..

Share Improve this question asked Jul 3, 2013 at 8:44 vikiviki 651 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Your XHTML is probably malformed.

Put your Javascript code into a CDATA section.

<script type="text/javascript">
    <![CDATA[
        alert("Your javascript here");
    ]]>
</script>
发布评论

评论列表(0)

  1. 暂无评论