【问题标题】:SyntaxError: Unexpected EOF语法错误:意外的 EOF
【发布时间】:2012-10-19 14:48:54
【问题描述】:

我将此代码添加到我的php 页脚中: 当我在 HTML 文档中使用相同的语法时,一切都很好。

   <body>
    ...

        <script type="text/javascript">     

        // Browser detection
        function checkBrowserName(name){ 
        var agent = navigator.userAgent.toLowerCase();  
        if (agent.indexOf(name.toLowerCase())>-1) {  
        return true;  
        }  
        return false;  
        }  

        if(checkBrowserName('opera')){
        /* load nothing */
        }

        else if(checkBrowserName('')) {
        /* else if(checkBrowserName('firefox') || ('msie') || ('safari') || ('konqueror') || ('omniweb') || ('webtv') || ('icab') || ('compatible')) { */

        // Insert script
        document.write('<script src="assets/javascripts/hyphenate.min.js" type="text/javascript"></script>');
        document.write('<\/script>');

        // Script options
        document.write('<script type="text/javascript">');
        document.write('Hyphenator.config({');
        document.write('displaytogglebox : false,');
        document.write('minwordlength : 4');
        document.write('});');
        document.write('Hyphenator.run();');
        document.write('<\/script>');

        }
        </script>
    ...
    </body>

我的换行符有问题吗?

当我编写这样的代码时,它会为我工作:

<script type="text/javascript" src="assets/javascripts/hyphenate.min.js"></script>
<script type="text/javascript">

Hyphenator.config({
    displaytogglebox : false,
    minwordlength : 4
});
Hyphenator.run();

</script>

感谢您的帮助
奥格尼

【问题讨论】:

  • 当您从网站复制/粘贴代码时,有时无效字符会进入代码。
  • 如何/在哪里/何时调用 checkBrowserName() ?
  • 我在你的代码中没有看到任何 PHP

标签: php javascript syntax-error line-breaks


【解决方案1】:

您不能将&lt;/script&gt; 写入字符串,因为此时解析将结束。
逃避它:

document.write('<script src="assets/javascripts/hyphenate.min.js" type="text/javascript"><\/script>');

(就像你其他时候所做的那样......)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 2013-01-29
    • 1970-01-01
    • 2023-04-07
    • 2018-08-06
    相关资源
    最近更新 更多