Changing input value while still allowing the user to type

后端 未结 2 857
鱼传尺愫
鱼传尺愫 2020-12-19 16:33

Is it possible, using JavaScript or jQuery, to change the content of a text input field while the user types?

E.g. typing a + up would change the

2条回答
  •  猫巷女王i
    2020-12-19 17:01

    I once had to do a similar thing. I think this is much simpler. Modify it to meet your needs:

    $("input#s").keyup(function(e) {
        var m=$("input#s");
        var value= m.val();
        var pos = m.prop('selectionStart');
        value=value.replace(">","»");
        m.val(value);
        m.prop({'selectionStart':pos,'selectionEnd':pos});
    });
    

提交回复
热议问题