[英]Change value of target textbox using function in javascript
I want to create a function to change the value of targeting textbox but I can't figure out what's wrong with my code. 我想创建一个函数来更改定位文本框的值,但是我无法弄清楚代码出了什么问题。
<form name="formcalc">
<input type="text" value="1" name="A" >
<input type="button" value="Change" onClick="change(A)">
<br>
<input type="text" value="2" name="B" >
<input type="button" value="Change" onClick="change(B)">
</form>
<script>
function change(x) {
document.formcalc.x.value = 3;
}
</script>
As you are sending the element directly to the function, below will work 当您将元素直接发送到函数时,下面的命令将起作用
function change(x) {
x.value = 3;
}
尝试在输入type = text中添加id属性,并使用进行调用
document.getElementById("nameId").innerHTML=yourdata...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.