jQuery keyup() illegal characters

前端 未结 3 1096
时光说笑
时光说笑 2021-01-25 17:08

I have a field and want to prevent some illegal characters while showing the user as he types. How can I do this in follow example?

  $(\'input\').bind(\"change          


        
3条回答
  •  孤独总比滥情好
    2021-01-25 17:18

    Give this a try. No array, though.

        $('input').bind("change keyup", function() {
            var $th = $(this);
            $th.val( $th.val().replace(/["<>&]/g, function(str) {  return ''; } ) );
        }); 
    

提交回复
热议问题