Javascript Chrome&;Internet Explorer

Javascript Chrome&;Internet Explorer,javascript,internet-explorer,Javascript,Internet Explorer,我有这个代码,它在谷歌浏览器中工作,但在IE浏览器中不工作 <html><head> <script type ="text/JavaScript"> <!-- function status() { var text = newArray(); text[0] = "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every mom

我有这个代码,它在谷歌浏览器中工作,但在IE浏览器中不工作

<html><head>
 <script type ="text/JavaScript">
<!--
function status()
{
    var text = newArray();
    text[0] = "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every moment; good, bad, happy, or sad;because the gift of life is LIFE itself";
    text[1] = "never design your character like a garden where any one can walk. but design your character like the sky, where everyone likes to reach you";
    text[2] = "Crying is never a symbol of weakness... From the time we are born, it has always been a sign that we are alive...";
    text[3] = "If you believe, you can achieve!";
    text[4] = "BELIEVE: To hope for the best, endure the stress, passing every test & accepting nothing less.";
    text[5] = "Never give up on your dreams and goals, if you do,your life end up no where.";
    text[6] = "The only thing that is guaranteed forever is your family... they will always be your family.. everything else can change.";
    var i = Math.floor(7*Math.random())
    var g=window.alert(text[i]);
    return g ;
}
//-->
</script>
</head></html>

newArray()应该是
新数组()
甚至更好,
[]

此外,JavaScript字符串中不能有换行符-将物理换行符替换为
\n

返回
alert()
newArray()的返回值也没有意义应该是
新数组()
甚至更好,
[]

此外,JavaScript字符串中不能有换行符-将物理换行符替换为
\n

返回
alert()

的返回值更改行也没有意义

var g=window.alert(text[i]);

换线

var g=window.alert(text[i]);

正确的代码是:
var text=new Array()

正确的代码是:
var text=new Array()

对于这类事情,数组文字通常是最好的选择:

var text = [
    "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every moment; good, bad, happy, or sad;because the gift of life is LIFE itself",
    "never design your character like a garden where any one can walk. but design your character like the sky, where everyone likes to reach you",
    "Crying is never a symbol of weakness... From the time we are born, it has always been a sign that we are alive...",
    "If you believe, you can achieve!",
    "BELIEVE: To hope for the best, endure the stress, passing every test & accepting nothing less.",
    "Never give up on your dreams and goals, if you do,your life end up no where.",
    "The only thing that is guaranteed forever is your family... they will always be your family.. everything else can change."
];
这将使用列出的条目创建一个新数组。数组条目用逗号分隔。最后一个条目后面没有逗号(如果你在那里放一个,一些浏览器会在数组末尾放一个无关的
未定义的
条目,因为规范过去很模糊;现在不再是了,但一些旧浏览器仍然有这个问题)


我记不起上一次实际编写
var a=new Array()
(注意空格)是什么时候了。即使对于空白数组,也要使用
var a=[]。它不仅更短,而且避免了数组被阴影遮挡的可能性。

对于这种情况,数组文字通常是最好的选择:

var text = [
    "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every moment; good, bad, happy, or sad;because the gift of life is LIFE itself",
    "never design your character like a garden where any one can walk. but design your character like the sky, where everyone likes to reach you",
    "Crying is never a symbol of weakness... From the time we are born, it has always been a sign that we are alive...",
    "If you believe, you can achieve!",
    "BELIEVE: To hope for the best, endure the stress, passing every test & accepting nothing less.",
    "Never give up on your dreams and goals, if you do,your life end up no where.",
    "The only thing that is guaranteed forever is your family... they will always be your family.. everything else can change."
];
这将使用列出的条目创建一个新数组。数组条目用逗号分隔。最后一个条目后面没有逗号(如果你在那里放一个,一些浏览器会在数组末尾放一个无关的
未定义的
条目,因为规范过去很模糊;现在不再是了,但一些旧浏览器仍然有这个问题)


我记不起上一次实际编写
var a=new Array()
(注意空格)是什么时候了。即使对于空白数组,也要使用
var a=[]。它不仅更短,而且避免了
Array
(符号)被阴影遮挡的可能性。

我将这样编写您的代码:

var status = function() {
    var text = [
        "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every moment; good, bad, happy, or sad;because the gift of life is LIFE itself"
        , "never design your character like a garden where any one can walk. but design your character like the sky, where everyone likes to reach you"
        , "Crying is never a symbol of weakness... From the time we are born, it has always been a sign that we are alive..."
        , "If you believe, you can achieve!"
        , "BELIEVE: To hope for the best, endure the stress, passing every test & accepting nothing less."
        , "Never give up on your dreams and goals, if you do,your life end up no where."
        , "The only thing that is guaranteed forever is your family... they will always be your family.. everything else can change."
    ], i = Math.floor(7*Math.random());
    alert(text[i]);
}

我会这样编写您的代码:

var status = function() {
    var text = [
        "Life is traveled only once..Today's moment becomes tomorrow's memory..Enjoy every moment; good, bad, happy, or sad;because the gift of life is LIFE itself"
        , "never design your character like a garden where any one can walk. but design your character like the sky, where everyone likes to reach you"
        , "Crying is never a symbol of weakness... From the time we are born, it has always been a sign that we are alive..."
        , "If you believe, you can achieve!"
        , "BELIEVE: To hope for the best, endure the stress, passing every test & accepting nothing less."
        , "Never give up on your dreams and goals, if you do,your life end up no where."
        , "The only thing that is guaranteed forever is your family... they will always be your family.. everything else can change."
    ], i = Math.floor(7*Math.random());
    alert(text[i]);
}

如果你展示代码,也许我们可以帮你!尝试在互联网上搜索。人们说有各种各样的信息可以找到。你知道什么?在chrome中工作而不是在ie中工作给了我们3300万个结果!代码在那里,海报没有使用代码格式,所以因为脚本标记而被隐藏。我把它和糟糕的拼写和句子结构一起修复了。:)您缺少
new
Array
之间的空格。这仅仅是一个印刷错误吗?如果你显示代码,也许我们可以帮助你!尝试在互联网上搜索。人们说有各种各样的信息可以找到。你知道什么?在chrome中工作而不是在ie中工作给了我们3300万个结果!代码在那里,海报没有使用代码格式,所以因为脚本标记而被隐藏。我把它和糟糕的拼写和句子结构一起修复了。:)您缺少
new
Array
之间的空格。这只是一个印刷错误吗?非常感谢。但它在internet explorer中不起作用。它在chrome中起作用。非常感谢。但它在internet explorer中不起作用。它在chrome中起作用。。。。。。。