1
<form name="test_form">
    <input id="demo" type="text" value=""> 
</form>



<button onclick="data()">GO</button>
<script>
var x=document.getElementById("demo");  
function data()
  {
    x.innerHTML="TEST"; 
  }
</script>

I am trying to input JavaScript function into input field but I've got a problem with that, nothing is happening, any ideas how to fix it?

4

2 回答 2

1
x.innerHTML="TEST"; 

should be

x.value="TEST"; 
于 2012-11-27T18:13:54.090 回答
0
<script>

function data()
{
  var x=document.getElementById("demo");
  x.value="TEST"; 
}
</script>
<form name="test_form">
  <input id="demo" type="text" value=""> 
</form>
<button onclick="data();">GO</button>

http://jsfiddle.net/vdAY7/

于 2012-11-27T19:03:25.637 回答