Javascript 更改输入字段onclick的值
我正在尝试使用单击的按钮的innerHtml更改输入值的值。。。我试过几种方法,但都不管用Javascript 更改输入字段onclick的值,javascript,input,Javascript,Input,我正在尝试使用单击的按钮的innerHtml更改输入值的值。。。我试过几种方法,但都不管用 <script> function changeValue(){ var cValue = document.getElementbyId('technician').innerHTML; var cType = document.getElementbyId('type'); var cType.value = cValue; } </scr
<script>
function changeValue(){
var cValue = document.getElementbyId('technician').innerHTML;
var cType = document.getElementbyId('type');
var cType.value = cValue;
}
</script>
<button id="technician" onclick="changeValue()">Technician</button>
<input type="" id="type" name="type" value="change"></input>
函数changeValue(){
var cValue=document.getElementbyId('technology').innerHTML;
var cType=document.getElementbyId('type');
var cType.value=cValue;
}
技术员
我也试过了
<script>
function changeValue(){
var cValue = document.getElementbyId('technician').innerhtml;
document.getElementbyId('type').value = ('cValue');
}
</script>
函数changeValue(){
var cValue=document.getElementbyId('technology').innerhtml;
document.getElementbyId('type')。value=('cValue');
}
这两种方法似乎都不起作用,这里有一个非常简单的方法:
函数更改值(值){
document.getElementById('button1')。innerHTML=value;
}
当您单击我时,我有一些内容将发生更改。
函数changeValue(){
document.getElementById('type').value=“就这样”;
}
我想这就是你想要的:
<script>
function changeValue(){
document.getElementById('technician').innerHTML = document.getElementById('type').value;
}
</script>
<button id="technician" onclick="changeValue()">Technician</button>
<input id="type" name="type" value="change"></input>
函数changeValue(){
document.getElementById('technology').innerHTML=document.getElementById('type').value;
}
技术员
您的代码中有几个拼写错误
大写字母和小写字母在getElementById和innerHTML中都很重要
我相信这就是你想要做的:
函数更改值(o){
document.getElementById('type')。value=o.innerHTML;
}
技术员
开发商
谢谢您的回答。我的问题是,当我打电话给var cVaue时,我附上了它
document.getElementbyId('type').value = ('cValue');
我什么时候应该有这样的代码
document.getElementbyId('type').value = cValue;
尝试innerText而不是innerHtml。如果这不起作用,请尝试使用document.getElementbyId('technology').value。我看不到您所指的打字错误。。。我能解决这个问题。。上面回答了。你的代码也可以工作。实际上比我的好。我的代码更重。Thankyoutypos字面意思是用小写字母代替大写字母。getElementbyId与getElementbyId不同。此外,innerhtml与innerHTMLthat在这个问题上是一个输入错误。。。很抱歉在实际代码中,它是正确的
document.getElementbyId('type').value = cValue;