javascript code not working in JSF xhtml page - Stack Overflow

Here is the running code on fiddleYou will see that It is working perfectly fine here but when I run th

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745591336a4634850.html

相关推荐

  • javascript code not working in JSF xhtml page - Stack Overflow

    Here is the running code on fiddleYou will see that It is working perfectly fine here but when I run th

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信