javascript中的按钮值显示未定义

时间:2013-04-24 18:02:31

标签: javascript button getelementsbytagname

[pure javascript code without the html body]
<script language="Javascript">
    [ creating buttons with the alphabets on it and its values the same]

  for(var a=1;a<=26;a++)
  {
  document.write("<input type='button' size='1' value="+String.fromCharCode(a +64)+" id='btn"+a+"' onclick='see()' >");
  }


document.write("<input type='text' size='10' id='box1' style='background-color:red'>")               

[normal textbox which should contain the data]
    function see()
      {
      [trying to put the value of button on textbox on buttonclick but gives me  undefined]


       var text;
       text=*document.getElementsByTagName*("button").value;
       document.getElementById("box1").value=text;
      }

</script>

我已经尝试过document.getElementsByTagName,或者甚至通过Id给出undefined,因为我希望文本框上的按钮值为.. 我使用了forloop,因为我必须创建大约26个按钮

1 个答案:

答案 0 :(得分:1)

"...value='" + String.fromCharCode(a +64) + "'..." 

您缺少单引号。