html和js的问题

时间:2013-09-16 23:16:12

标签: javascript html external

这太令人沮丧了。我参加了W2school教程,其中提供了点点滴滴,但它没有回答如何将它们放在一起。我以为我明白了,但是当我把它付诸实践时,什么都没有。 Firebug告诉我inputEmp()没有定义,但很明显在.js文件中定义。有人可以告诉我我遗漏了哪些细节?首先感谢Html,然后是.js文件。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/payroll.css" />

<title>Payroll System</title>

<script type="text/javascript" src="scripts/payroll.js"></script> 

<script type="text/javascript" >
    var emps = new Array();
</script>   
</head>

<body>
  <h1>Jackson Payroll System</h1>
  <button type="button" onclick="inputEmp()">
    Click here to enter employees
  </button>
</body>
</html>

// payroll.js
function inputEmp() {
    var inName = "";
    var loopCt = 0
    var tArray = new Array();

    while (inName != "-1}
    {
        prompt inName = prompt("Please enter your name (enter -1 to finish)",
                               "Employee Name");
    if (inName == "-1")  { break; }
    if (inName==null || inName=="")
    {
        alert("Blank names are not allowed.  To exit enter '-1'.");
    } 
    else
        tArray[loopCt++] = inName;
    {

    }
    return tArray;
}   

2 个答案:

答案 0 :(得分:0)

是的,你忘了在return语句之前关闭{while循环的括号{。并且报价未在条件下关闭。

试试这个

    function inputEmp() {
    var inName = "";
    var loopCt = 0
    var tArray = new Array();

    while (inName != "-1"} {
        prompt inName = prompt("Please enter your name (enter -1 to finish)","Employee Name");
    if (inName == "-1")  { break; }
    if (inName==null || inName=="")
        {
        alert("Blank names are not allowed.  To exit enter '-1'.");
        } 
    else
        tArray[loopCt++] = inName;
    {

    }
    }
    return tArray;
    }   

答案 1 :(得分:0)

您的代码中存在很多问题:

var loopCt = 0应该如下var loopCt = 0;

while (inName != "-1}应该如下while (inName != "-1)

prompt inName = prompt...应该如下inName = prompt...

else语句

下有一个空的{ }

这是一个显示更正代码的jsfiddle