注册 登录
编程论坛 JavaScript论坛

函数运行不了,求助

丶木清丶 发布于 2017-11-28 23:18, 2186 次点击
这段函数运行不了,不明白哪里出错了,请大家帮忙看一下,感谢。

//loops.html文件
<html>
    <head>
        <title>
            LOOPS Example
        </title>
    </head>
    <body>
        <h1>Loop Example</h1>
        <p>Enter a series of names,I will then display them in a nifty numbered list.</p>
        <script language="javascript" type="text/javascript" scr="loops.js"></script>
    </body>
</html>

//loops.js文件
// JavaScript source code
names = new Array();
i = 0;
do {
    next = window.prompt("Enter the Next Name", "");
    if (next > " ")
        names[i] = next;
    i = i + 1;
} while (next > " ");
document.write("<h2>" + (names.length) + "names entered.</h2>");
document.write("<ol>");
for (i in names)
{
    document.write("<li>" + names[i] + "<br>");
}
document.write("</ol>");
2 回复
#2
leeqihero2018-03-01 08:30
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<h1>Loop Example</h1>
<p>Enter a series of names,I will then display them in a nifty numbered list.</p>
</body>
<script>
names = new Array();
i = 0;
do {
    next = window.prompt("Enter the Next Name", "");
    if (next > " ")
        names[i] = next;
    i = i + 1;
} while (next > " ");
document.write("<h2>" + (names.length) + "names entered.</h2>");
document.write("<ol>");
for (i in names)
{
    document.write("<li>" + names[i] + "<br>");
}
document.write("</ol>");
</script>
</html>
只有本站会员才能查看附件,请 登录
#3
leeqihero2018-03-01 08:56
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<h1>Loop Example</h1>
<p>Enter a series of names,I will then display them in a nifty numbered list.</p>
</body>
<script>
var names = [];
var n=""
var html="";
while(1){
    n = window.prompt("Enter the Next Name", "");
    if (!n) break;
    names.push(n);
};
html+="<h2>" + (names.length) + "names entered.</h2><ol>";
for (var i in names){
    html+="<li>" + names[i] + "<br>";
}
html+="</ol>"
document.body.innerHTML+=html;
</script>
</html>
1