Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我不能改变输入值_Javascript_Html_Forms_Input_Calculator - Fatal编程技术网

Javascript 我不能改变输入值

Javascript 我不能改变输入值,javascript,html,forms,input,calculator,Javascript,Html,Forms,Input,Calculator,我想创建Javascript简单计算器,我想在单击时更改标记的值,我使用了这个 document.getElementById('input').value = "1" 但是它只键入一次1,因此我无法键入11或111。问题是什么?你能帮我吗?我不知道这是不是正确答案,因为OP的代码没有提供 var el=document.getElementById('input'); el.value=1; var button=document.getElementById('按钮') button.

我想创建
Javascript
简单计算器,我想在单击时更改
标记的值,我使用了这个

document.getElementById('input').value = "1" 

但是它只键入一次1,因此我无法键入11111。问题是什么?你能帮我吗?

我不知道这是不是正确答案,因为OP的代码没有提供

var el=document.getElementById('input');
el.value=1;
var button=document.getElementById('按钮')
button.onclick=函数(){
el.value=parseInt(el.value)+1;
}


加1首先,您必须将该字段的值作为

var val = document.getElementById('input').value;
然后添加一个值并在其中显示为

document.getElementById('input').value = val + 1;
以下是完整的运行代码:

函数名(参数){
var val=document.getElementById('input')。值;
document.getElementById('input')。value=val+1;
}


按1你能分享完整的代码吗?试试document.getElementById('input')。value=document.getElementById('input')。value+1;谢谢你的帮助,这不是我想要的答案,我想在每次推送时加上“1”,例如“1”“11”“111”@Y。Vahe当你问这个问题时,你接受了我的答案,答案是根据你想要的答案。那么,为什么你以后会将其标记为不可接受呢。我能知道原因吗?