日期:2014-05-16  浏览次数:20370 次

啊!完全要疯了,关于js switch语句。!
刚开始学习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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>ok</title>
<script type="text/javascript" src="js.js"></script>
</head>

<body>
<form action="#" >
  <input type="button" id="Nihao" value="你好" /> 
  <input type="button" id="Woqu" value="我好" />
  <input type="button" id="Dajiahao" value="大家好" />
</form>
</body>
</html>




window.onload = initAll;

function initAll() {
document.getElementById("Nihao").onclick = chuLi;
document.getElementById("Wohao").onclick = chuLi;
document.getElementById("Dajiahao").onclick = chuLi;
}
function chuLi() {
switch (this,id) {
case "Nihao":
  alert("你好");
  break;
case "Wohao":
  alert("我好");
  break;
case "Dajiahao":
  alert("ssssss");
  break;
default:
}
}


有什么遗漏掉的吗???

空格什么的应该没差吧??

会不会是函数名的问题??

想了半天,没想出来。。。。。。

------解决方案--------------------
大哥,你怎么把点好写成逗号了你这样怎么能做出来呢?

------解决方案--------------------
 switch (this,id)