我遇到了我的代码问题。 没有发生函数f和g不叫,我只是想传递数组到一个函数,做的东西吧:功能在javascript中不起作用
<html>
<head>
<title>test</title>
</head>
<body>
<script lang="JavaScript" type="text/javascript">
// l = prompt("Your name :"); // if i remove the comment it works
function f(E) {
l = prompt("Your name :");
E["Name"] = l;
l = prompt("Your Age :");
E["Age"] = l;
l = prompt("Your Note :");
E["Note"] = l;
}
// l = prompt("Your name :"); // if i remove the comment it works
function g(E) {
for (ind in E) {
document.write("E[" + ind + "]=" + E[ind]);
}
}
E = newarray(3);
//l = prompt("Your name :"); // here if i remove the comment nothing happen
f(E);
g(E);
</script>
</body>
</html>
您的代码使用的是一个名为'newarray'的函数,它在您所显示的代码中没有定义。如果你看看你的Web控制台,你会看到一个很好的,明确的错误信息,指向失败的那一行。 –
“没有任何事情”是不完全正确的(也语法;-)) - 您的代码中有一个错误,防止进一步执行。你应该看看JS控制台(不同的方式来访问它取决于浏览器)看到err-msg .... – MBaas