How can I enter a text box and have what I typed at the same time in a div?

I want it to be when I enter a text field (or input field) and everything that I type is displayed in a div at the same time or just somewhere else on the page?

The stackoverflow site does this when we enter a question. When we enter a question, it shows what we type in the box below the text box. Hope my question makes sense!

Thanks in advance.

+3
source share
3 answers

StackOverflow , , - keydown (), keypress keyup ( , ) . .

- keyup (keydown keypress). , key(press|down) - , , , . keyup, , . , keyup , , , . , :)

$("textarea").bind('keyup keydown', function() {
    $("#target").html(this.val());
});

. .

+7

.keydown() :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        $('#foo').keydown(function() {
            $('#result').text($(this).val());
        });
    });
    </script>
</head>
<body>
    <input type="text" name="foo" id="foo" />
    <div id="result"></div>
</body>
</html>
+2

... , .

View Source:

:

<script type="text/javascript">
    $(function() { 
        editorReady(1, heartbeat.answers);
    });   
</script>

URL "editorReady".   http://sstatic.net/js/question.js?v=b05e8725a843

+1

Source: https://habr.com/ru/post/1756377/


All Articles