keydown为什么keyup没有返回false?

时间:2015-09-12 07:33:06

标签: javascript jquery keydown keyup

return false为什么keyup事件在keydown事件中无法正常工作。

请参阅 KeyDown事件的此片段:



var max = 10;
$('#txt').keydown(function(e) {
  var keycode = e.keyCode;
      
  var printable = 
      (keycode > 47 && keycode < 58)   || // number keys
      keycode == 32 || keycode == 13   || // spacebar & return key(s) (if you want to allow carriage returns)
      (keycode > 64 && keycode < 91)   || // letter keys
      (keycode > 95 && keycode < 112)  || // numpad keys
      (keycode > 185 && keycode < 193) || // ;=,-./` (in order)
      (keycode > 218 && keycode < 223);   // [\]' (in order)
 
  if (printable) {
    return $(this).val().length < max;
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type = "text" id = "txt">
&#13;
&#13;
&#13;

KeyUp事件

的代码段

&#13;
&#13;
var max = 10;
$('#txt').keyup(function(e) {
  var keycode = e.keyCode;
      
  var printable = 
      (keycode > 47 && keycode < 58)   || // number keys
      keycode == 32 || keycode == 13   || // spacebar & return key(s) (if you want to allow carriage returns)
      (keycode > 64 && keycode < 91)   || // letter keys
      (keycode > 95 && keycode < 112)  || // numpad keys
      (keycode > 185 && keycode < 193) || // ;=,-./` (in order)
      (keycode > 218 && keycode < 223);   // [\]' (in order)
 
  if (printable) {
    return $(this).val().length < max;
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type = "text" id = "txt">
&#13;
&#13;
&#13;

有人可以向我解释原因吗?感谢。

0 个答案:

没有答案