javascript中的按钮值显示未定义
button value in javascript shows undefined
[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>
我已经试过了。getElementsByTagName或甚至由Id给出未定义的地方,因为我想要按钮的值在文本框上。我使用了forloop,因为我必须创建大约26个按钮
"...value='" + String.fromCharCode(a +64) + "'..."
您缺少了单引号
相关文章:
- 敲除jsobservable显示未定义的值
- 使用eval()定义变量显示未定义的错误
- 当使用多个false时,Select2显示未定义
- 函数在控制台中显示“未定义”
- 在文本区域显示未定义的javascript数组
- this.value在<td>标记显示未定义
- Chrome 显示未定义密钥代码
- 节点.js 使用 Multer 上传图像显示未定义
- 语句的 Javascript 一直显示未定义
- 显示未定义值的工具提示
- 为什么它在数组之前显示未定义
- Ajax 结果显示未定义
- 显示“未定义”的 JS 警报
- 样式.在元素正确定义时显示未定义
- 它一直显示未定义的文件名
- jQuery每个函数和数组在for循环中显示未定义
- Hapi在处理程序中显示未定义的变量
- 选择2显示未定义
- Json数组只显示未定义的未定义
- 来自文本框和单选按钮的用户输入在警报中重复,显示未定义