如何获取Textfield值以显示在屏幕上的所需位置

时间:2013-03-16 00:54:04

标签: javascript html

单击更改文本时,我需要在屏幕的另一部分显示我的文本字段值。我怎么能这样做?

<div id="placetextfield">
  <script>
    var textfield = "Enter text on shirt:"; 
    textfield = textfield.bold()
    textfield = textfield.fontsize(5)
    document.write("<p>"  + textfield.fontcolor("#FF6600") + "</p>");
  </script>

  <script type="text/javascript">
    function changeText2(){
      var userInput = document.getElementById('userInput').value;
      document.getElementById('textfield').innerHTML = userInput;
    }
  </script>

  <b id='textfield'></b>
  <input type='text' id='userInput'/>
  <input type='button' onclick='changeText2()'value='Change Text'/>
</div>

1 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
function changeText2(){
    var userInput = document.getElementById('userInput').value;
    document.getElementById('yourId').innerHTML = userInput;
}
</script>
<b id='textfield'></b>
<input type='text' id='userInput'/>
<input type='button' onclick='changeText2()'value='Change Text'/>