更改输入字段的值onclick

tru*_*tru 3 javascript input

我试图用点击的按钮的innerHtml更改输入值的值...我尝试了几种方法,但没有一个工作

<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>
Run Code Online (Sandbox Code Playgroud)

我也试过了

<script>
   function changeValue(){
     var cValue = document.getElementbyId('technician').innerhtml;
     document.getElementbyId('type').value = ('cValue');
    }
</script>
Run Code Online (Sandbox Code Playgroud)

似乎都没有起作用

小智 5

你的代码大写中有几个拼写错误,小写字母在getElementById和innerHTML之类的内容中很重要

我相信这就是你要做的事情:

<script>
   function changeValue(o){
     document.getElementById('type').value=o.innerHTML;
    }
</script>

<button id="technician" onclick="changeValue(this)">Technician</button>
<button id="developer" onclick="changeValue(this)">Developer</button>
<input type="text" id="type" name="type" value="change" />
Run Code Online (Sandbox Code Playgroud)