Validate html text input as it's typed

前端 未结 9 665
再見小時候
再見小時候 2020-11-27 16:36

What\'s the best way of validating an HTML text input as it\'s typed? All ways I know of doing it has some drawbacks:

  1. Using $.keypress you only

9条回答
  •  [愿得一人]
    2020-11-27 17:09

    You can use the input (FF) and propertychange (all others) events to catch all forms of input including keyboard and rmb cut paste.

    http://jsfiddle.net/dFBzW/

    $('input').bind('input propertychange', function() {
        $('#output').html($(this).val());
    });
    

提交回复
热议问题