Javascript呈现不正确

时间:2013-09-06 19:43:32

标签: javascript jsf jsf-2

所以,我正在使用JSF 2.0,我已经创建了一个如下所示的JavaScript:

            <script type="text/javascript">
                    function generate(){
                        if(!licenseServerInfo){
                            NI.pnx.messaging.popMessage(NI.pnx.messaging.messageTypes.warning,['<strong>Your changes to License Server Name and Computer ID have not been saved.</strong><a href="" class="right"><strong>Undo Change</strong></a>'],NI.pnx.messaging.messageTimeoutSpeeds.never);
                        }else{
                            generateLicenseFile();
                            document.getElementById('upperButtons:generateCall').click();
                        }
                    }                   
            </script>

但它的呈现方式如下:

<script type="text/javascript"><!--

                    function generate(){
                        if(!licenseServerInfo){
                            NI.pnx.messaging.popMessage(NI.pnx.messaging.messageTypes.warning,['<strong>Your changes to License Server Name and Computer ID have not been saved.
//--></strong><a class="right"><strong>Undo Change<!--

                    function generate(){
                        if(!licenseServerInfo){
                            NI.pnx.messaging.popMessage(NI.pnx.messaging.messageTypes.warning,['<strong>Your changes to License Server Name and Computer ID have not been saved.
//--></strong><!--

                    function generate(){
                        if(!licenseServerInfo){
                            NI.pnx.messaging.popMessage(NI.pnx.messaging.messageTypes.warning,['<strong>Your changes to License Server Name and Computer ID have not been saved.
//--></a>'],NI.pnx.messaging.messageTimeoutSpeeds.never);
                        }else{
                            generateLicenseFile();
                            document.getElementById('upperButtons:generateCall').click();
                        }
                    }

                <!--

                    function generate(){
                        if(!licenseServerInfo){
                            NI.pnx.messaging.popMessage(NI.pnx.messaging.messageTypes.warning,['<strong>Your changes to License Server Name and Computer ID have not been saved.
//--></script>

使用chrome的控制台,如果我调用每个包含的函数,它们都可以正常工作。但是,如果我尝试调用generate(),它会说它不存在。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

一方面,它看起来你正在循环中生成该代码(这就是为什么函数被多次写入)。另一方面,您可以尝试在<![CDATA[ ]]>内设置脚本以避免浏览器尝试解析它