为什么我的网站中的脚本得到这个错误? [英] Why I am getting this error with the script in my website?

查看:112
本文介绍了为什么我的网站中的脚本得到这个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过添加以下一堆代码建议由我的网站中的JQuery LavaLamp菜单栏面临的问题,一个惊人的开发人员和这个社区的人:

I am trying to fix the problem that I am facing with JQuery LavaLamp Menu Bar in my website by adding the following bunch of code suggested by one of the amazing developers and people in this community:

<script>
if ($.browser.version < 9.0 && $.browser.msie) {
document.getElementsByTagName("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js"></script><script type="text/javascript"  src="./Scripts/jquery.lavalamp.js"></script><script type="text/javascript" src="./Scripts/lavalamp-config.js"></script>';
}
else {
    document.getElementById("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js">';
}

​​</script>​​​​​​​​​​​​​​​​​​​​​​​​​​​

在Visual Studio 2010中,出现以下错误

And in the Visual Studio 2010, I got the following error


未终止的字符串常量

Unterminated string constant

下面一行:

document.getElementsByTagName("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js"></script><script type="text/javascript"  src="./Scripts/jquery.lavalamp.js"></script><script type="text/javascript" src="./Scripts/lavalamp-config.js"></script>';

那么我该如何解决这个问题?

UPDATE#1:

我将代码更新为您建议的内容,同样的错误。此外,以下是错误的快照:

I updated my code to what you suggested guys and I am still getting the same error. Also, here's a snapshot of the error:

UPDATE#2
我修改了我的代码,让主页包含以下代码,获得与上面快照中显示的页面顶部显示的相同的错误。

UPDATE #2 I modified my code to let the Master Page includes the following code and I am still getting the same error that shows at the top of the page as shown in the above snapshot.

<head>
<script type="text/javascript">
function getInternetExplorerVersion()
    // Returns the version of Internet Explorer or a -1
    // (indicating the use of another browser).
    {
        var rv = -1; // Return value assumes failure.
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var ua = navigator.userAgent;
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null)
                rv = parseFloat(RegExp.$1);
        }
        return rv;
    }
</script>

<script type="text/javascript">
 if (getInternetExplorerVersion() < 9.0 && browser_type  = "Microsoft Internet Explorer") {
    document.getElementsByTagName("head")[0].innerHTML = "<script  type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'></script><script type='text/javascript'  src='./Scripts/jquery.lavalamp.js'></script><script type='text/javascript' src='./Scripts/lavalamp-config.js'></script>";
 }  else {
       document.getElementById("head")[0].innerHTML = "<script type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'>";
   }
​​</script>​​​​​​​​​​​​​​​​​​​​​​​​​​​
</head>


推荐答案

结束脚本标记很可能被浏览器解释作为当前脚本块的结尾,即使它们在一个字符串文字内,这反过来意味着特定的字符串文字是未终止的。

The closing script tags are likely being interpreted by the browser as the end of the current script block even though they're inside a string literal, which in turn means that particular string literal is unterminated.

'</script>'

您可以

'<\/script>'

(当JS运行时,反斜杠被忽略。)或者有时你会看到:

(When the JS runs the backslash is ignored.) Or sometimes you see something like:

'<' + '/script>'


b $ b

或用等效字符代码替换<

'\x3C/script>'

这篇关于为什么我的网站中的脚本得到这个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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