语法错误:意外的EOF [英] SyntaxError: Unexpected EOF

查看:131
本文介绍了语法错误:意外的EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I add this code into my php footer: When I use the same syntax in an HTML document everything works well for me.

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

换行符出问题了吗?

当我编写这样的代码时,它将对我有用:

When I write the code like this, it will work for me:

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

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

</script>

感谢您的帮助
奥格尼

Thanks for your help
Ogni

推荐答案

您不能将</script>写入字符串,因为解析到此为止. 逃脱吧:

You cannot write </script> into strings, because parsing ends at this point then.
Just escape it:

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

(就像您其他时候一样...)

(like you did the other times...)

这篇关于语法错误:意外的EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆