6

次のjQuery関数があります

jQuery.fn.integerMask =
function () {
return this.each(function () {
  $(this).keydown(function (e) {
    var key = (e.keyCode ? e.keyCode : e.which);
    // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
    return (
              key == 8 ||
              key == 9 ||
              key == 46 ||
              key == 37 ||
              key == 39 ||
              (key >= 48 && key <= 57) ||
              (key >= 96 && key <= 105));
              );
      });
    });
  };

数字の入力に使用します。問題は、SHIFT+8 でアスタリスク * 文字が入力されることです。SHIFTと組み合わせた「8」キーが許可されているようです。SHIFT+8 が受け入れられず、「*」文字が挿入されないようにするにはどうすればよいですか?

4

1 に答える 1

-1
<!DOCTYPE html>
<html>
<head>
<script>
function isKeyPressed(event)
{
if (event.shiftKey==1)
  {
  alert("The shift key was pressed!");
  }
else
  {
  alert("The shift key was NOT pressed!");
  }
}
</script>
</head>

<body onmousedown="isKeyPressed(event)">

<p>Click somewhere in the document. An alert box will tell you if you pressed the shift key or not.</p>

</body>
</html>

キーワード-> event.shiftKey

ソース: http://www.w3schools.com/jsref/tryit.asp?filename=try_dom_event_shiftkey

于 2014-07-02T02:49:47.490 に答える