<!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=gb2312" />
<title>无标题文档</title>
    <script type="text/javascript">
        function Click(var n)
        {
            var text=document.getElementById("txtDesc");
            switch(n)
            {
                case "1":text.value=text.value+"c[1]";
                         break;
                case "2":text.value=text.value+"c[2]";
                         break;
                case "3":text.value=text.value+"c[3]";
                         break;
                case "4":text.value=text.value+"c[4]";
                         break;
                case "5":text.value=text.value+"c[5]";
                         break;
                case "6":text.value=text.value+"c[6]";
                         break;
                case "7":text.value=text.value+"c[7]";
                         break;
                case "8":text.value=text.value+"c[8]";
                         break;
            }
        }
    </script></head><body>
<input type="button" value="OK" onclick="function(){Click(1);}" />
<input type="text" id="txtDesc" />
</body>
</html>我想通过按钮给函数传递个参数就是1,为什么FF老是报错?

解决方案 »

  1.   

    <input type="button" value="OK" onclick="Click(1)" /> 
    这样就足够了
      

  2.   

    case用数字的123,不要用"1","2"这样子
      

  3.   

    function Click(n)<input type="button" value="OK" onclick="Click(1)" /> 
      

  4.   

    <!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=gb2312" /> 
    <title>无标题文档 </title> 
        <script type="text/javascript"> 
            function Click(n) 
            { 
                var text=document.getElementById("txtDesc"); 
                text.value += "c["+n.toString()+"]"; 
            } 
        </script> </head> <body> 
    <input type="button" value="OK" onclick="Click(1)" /> 
    <input type="text" id="txtDesc" /> 
    </body> 
    </html> 
      

  5.   

     case "1":text.value=text.value+"c[1]"; <input type="button" value="OK" onclick="function(){Click(1);}" /> 一个是 "1"
    一个是 1貌似类型不对啦
      

  6.   

    <input type="button" value="OK" onclick="Click('1')" />