简体   繁体   English

Uncaught SyntaxError:意外的令牌非法

[英]Uncaught SyntaxError: Unexpected token ILLEGAL

I work with liferay 5.2 我使用Liferay 5.2

I want to display same message related to the current language of liferay 我想显示与liferay当前语言相关的相同消息

the code of this message is in the velocity lnaguage 该消息的代码在速度语言中

this is the source code navigation.vm 这是源代码navigation.vm

<div id="navigation" class="sort-pages modify-pages">
    <ul>
        #foreach ($nav_item in $nav_items)

            #if (($nav_item.getTitle() == 'register_correspondence') )
                    #if ($nav_item.hasChildren())
                        #foreach ($nav_child in $nav_item.getChildren())
                          <li >
                            <a href="$nav_child.getURL()" $nav_child.getTarget()>
                                <span >$nav_child.getName()</span>
                            </a>
                          </li>
                        #end
                    #end

            #end

            #if (($nav_item.getTitle() == 'reports') )      
              #if ($nav_item.isSelected())
                #set ($nav_item_class = "selected")
            #else
                #set ($nav_item_class = "")
            #end

            <li>

                #if (($nav_item.getTitle() == 'logout'))
                    <a href="$sign_out_url" $nav_item.getTarget()>
                        <span class="$nav_item.getTitle()">$nav_item.getName()</span>
                    </a>
                #else
                    <a href="$nav_item.getURL()" $nav_item.getTarget()>
                        <span class="$nav_item.getTitle()">$nav_item.getName()</span>
                    </a>
                #end

                #if ($nav_item.hasChildren())
                    <ul class="child-menu">
                        #foreach ($nav_child in $nav_item.getChildren())
                            #if ($nav_child.isSelected())
                                #set ($nav_child_class = "selected")
                            #else
                                #set ($nav_child_class = "")
                            #end

                            <li class="$nav_child_class">
                                <a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
                            </li>
                        #end
                    </ul>

                #end

            </li>#end
            #end
            #if ($show_sign_out)
            <li class="$nav_child_class">
                <A HREF="$sign_out_url" onCLick="return confirm(' Are you sure you want to log out ')"> <font color="FF0000">
                Logout
                </font>
                </A>
            </li>

        #end
    </ul>
</div>

my message is in this balise 我的信息就在这个阳台上

<li class="$nav_child_class">
                <A HREF="$sign_out_url" onCLick="return confirm(' Are you sure you want to log out ')"> <font color="FF0000">
                Logout
                </font>
                </A>
            </li>

I want to displya this message ralated to the current language of liferay 我想散布这条与Liferay当前语言有关的消息

meaning when the language is french the message will be displayed in the french 意思是当语言是法语时,该消息将以法语显示

I try without succes with this code : 我尝试使用此代码成功:

<div id="navigation" class="sort-pages modify-pages">
    <ul>
        #foreach ($nav_item in $nav_items)

            #if (($nav_item.getTitle() == 'register_correspondence') )
                    #if ($nav_item.hasChildren())
                        #foreach ($nav_child in $nav_item.getChildren())
                          <li >
                            <a href="$nav_child.getURL()" $nav_child.getTarget()>
                                <span >$nav_child.getName()</span>
                            </a>
                          </li>
                        #end
                    #end

            #end

            #if (($nav_item.getTitle() == 'reports') )      
              #if ($nav_item.isSelected())
                #set ($nav_item_class = "selected")
            #else
                #set ($nav_item_class = "")
            #end

            <li>

                #if (($nav_item.getTitle() == 'logout'))
                    <a href="$sign_out_url" $nav_item.getTarget()>
                        <span class="$nav_item.getTitle()">$nav_item.getName()</span>
                    </a>
                #else
                    <a href="$nav_item.getURL()" $nav_item.getTarget()>
                        <span class="$nav_item.getTitle()">$nav_item.getName()</span>
                    </a>
                #end

                #if ($nav_item.hasChildren())
                    <ul class="child-menu">
                        #foreach ($nav_child in $nav_item.getChildren())
                            #if ($nav_child.isSelected())
                                #set ($nav_child_class = "selected")
                            #else
                                #set ($nav_child_class = "")
                            #end

                            <li class="$nav_child_class">
                                <a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
                            </li>
                        #end
                    </ul>

                #end

            </li>#end
            #end
            #if ($show_sign_out)

    <script type="text/javascript">

        var varlang = "$themeDisplay.getLocale()";

        if( varlang == 'en_US') {

        document.write('<li class="$nav_child_class">
                <A HREF="$sign_out_url" onCLick="return confirm(' Are you sure you want to log out ')"> <font color="FF0000">
                Logout
                </font>
                </A>
            </li>');

        }
        else
        {

        document.write('<li class="$nav_child_class">
                <A HREF="$sign_out_url" onCLick="return confirm(' Etes-vous sûr que vous voulez vous déconnecter ')"> <font color="FF0000">
                Déconnexion
                </font>
                </A>
            </li>');

        }

        </script>


        #end
    </ul>
</div>

I make my test in the javascript code I add this line var varlang = "$themeDisplay.getLocale()"; 我在javascript代码中进行了测试,添加了以下代码行var varlang =“ $ themeDisplay.getLocale()”;

but when I test I have this error : 但是当我测试我有这个错误:

Uncaught SyntaxError: Unexpected token ILLEGAL 

I only changes the code in this section 我只更改此部分中的代码

#if ($show_sign_out) #if($ show_sign_out)

Your error is javascript error inside your script tag. 您的错误是脚本标记内的javascript错误。

This is not valid 这是无效的

document.write('<li class="$nav_child_class">
        <A HREF="$sign_out_url" onCLick="return confirm(' Are you sure you want to log out ')"> <font color="FF0000">
        Logout
        </font>
        </A>
    </li>');

for two reasons. 有两个原因。

Problem number one is that strings cannot span acros multiple lines. 第一个问题是字符串不能跨越多行杂音。

Second problem is that you have single quotes inside your string that you started with single quotes, you must escape inner single quotes. 第二个问题是,在以单引号开头的字符串中有单引号,因此必须转义内部的单引号。

You should rewrite it as 您应该将其重写为

document.write('<li class="$nav_child_class"><A HREF="$sign_out_url" onCLick="return confirm(\' Are you sure you want to log out \')"> <font color="FF0000">Logout</font></A></li>');

or at least as 或至少

document.write('<li class="$nav_child_class">' +
        '<A HREF="$sign_out_url" onCLick="return confirm(\' Are you sure you want to log out \')"> <font color="FF0000">' +
        'Logout' +
        '</font>' +
        '</A>' +
    '</li>');

But why do you do it with script tag? 但是,为什么要使用脚本标签呢?

I would rather have somthing like 我宁愿有这样的东西

#if ($show_sign_out)

    #if ($themeDisplay.getLocale() == "en_US")
        #set($logoutLabel = "Logout")
        #set($logoutConfirm = "Are you sure you want to log out")
    #else
        #set($logoutLabel = "Déconnexion")
        #set($logoutConfirm = "Etes-vous sur que vous voulez vous déconnecter")
    #end    

    <li class="$nav_child_class">
        <A HREF="$sign_out_url" onCLick="return confirm('$logoutConfirm')"> <font color="FF0000">
            $logoutLabel
        </font></A>
    </li>

#end 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM