V
V
vvmgev2016-03-03 21:48:05
JavaScript
vvmgev, 2016-03-03 21:48:05

How to get synchronous printing?

here i have this code

var input = $("input");
    var p = $("p");

    input.on('keyup',function(){
      var val = input.val();
      p.text(val);
    });


this method is not much slow if you are careful ... and if you press the key and do not release it will print after that
I want to achieve it like in angular

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2016-03-03
@Vovchikvoin

Firstly, Google Translator expresses your thoughts more clearly, and secondly, put a keydown event.

E
Ernest Faizullin, 2016-03-03
@erniesto77

now I know how English-speaking people see my questions on stackoverflow))
on the topic, try the input propertychange event

input.on('input propertychange', function() {
    var val = $(this).val();
    p.text(val);
});

A
Arthur, 2016-03-03
@astralo

Vladimir is right. put a keydown event handler, paste
the new character will be in the event that jquery passes

$(function(){
  var input = $("input");
  var p = $("p");
  
  input.on('keydown paste',function(e){
    var newval = input.val()+String.fromCharCode(e.keyCode);
    p.text(newval);
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question