简体   繁体   中英

How to insert text into table with input field

This is the html code

        <input type="text" id="input"/>
    <table>
        <tr>
            <td id="output"></td>
        </tr>
    </table>
<input type="button" id="submit" value="Submit">

And javascript

$("#submit").click(function(){

  var input = document.getElementById("input").innerhtml;
  document.getElementById("output").innerHTML = input;

});

This javascript does't work whats the correct code?

Looks like you're using jQuery . You can refactor your javascript to this:

$("#submit").click(function(e) {
  var inputValue = $('#input').val();
  $('#output').text(inputValue);
});

If you are using jquery use this.

$('#output').html('your input text');

if you are using native javascript use this

document.getElementById("output").html('your input text');

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM