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

为什么javascript里面的函数没反应,没调用到吗?
<html>
 <head>
  <title> New Document </title> 
 </head>

 <body>
  <script type="text/javascript">
  alert("zhegjkglkjasg");
  for(int i=0;i<6;i++)
  {
  alert("fhkl");
  document.write("<input type="button" value="button" onclick="Button(i)"/>");
  }
  function Button(int i)
  {
  alert(""按钮"+i"");
  }
  </script>

 <p> hlkhdlkshfdsahgd</p>
 <input type="button" value="button" onclick="Button(1)"/>
 </body>
</html>

为什么javascript里面的东西完全没有用的,新手求救~勿喷~

------解决方案--------------------
JScript code
<html>
  <head>
   <title> New Document </title>  
 </head>

  <body>
   <script type="text/javascript">
   alert("zhegjkglkjasg");
   for(var i=0;i<6;i++)// int ,靠~~
   {
   alert("fhkl");
   document.write("<input type=\"button\" value=\"button\" onclick=\"Button("+i+")\"/>");
   //双引号不要和双引号一起用,你如果想要一起用,把里面的用转义字符处理,或者直接使用单引号
   //因为上式的i是变量,所以~~~这个真是难讲,你这个都还不会处理,还是要多看看js基础啊
   }
   function Button(i)//int不是js里面的类型,真是蛋疼了~~可以不做定义的
   {
   alert("按钮="+i);
   //这个地方,算是个什么错误啊~~~~~~~~
   }
   </script>

  <p> hlkhdlkshfdsahgd</p>
  <input type="button" value="button" onclick="Button(1)"/>
  </body>
</html>