English 中文(简体)
当信件打入表格时,如何停止键盘功能的射击?
原标题:How to stop keyboard functions from firing when the letters are typed in a form?

我有一个在键盘按下“ N” 键和“ P” 键时向下一个/ prev 滚动的脚本。 我的问题是, 当用户通常以任何形式( 如搜索字段、 登录字段等) 键入这些字母时, 如何阻止它射击 。 因为当我按下, 例如 John 这样的窗体时, 它不会写 N, 反而会点燃滚动函数 。 如何修正该动作?

我的代码如下:

$(document).keydown(function (evt) {
    if (evt.keyCode == 78) {
        evt.preventDefault();
        scrollToNew();
    } else if (evt.keyCode == 80) {
        evt.preventDefault();
        scrollToLast();
    }
});

谢谢

最佳回答
问题回答

我觉得有点像

$( form ).on( keydown , function(event) {event.stopPropagation();});

如果您不需要窗体内键盘控件, 应该玩这个把戏 。

使用 < a href=" < a href="的 target 属性" https:// developer.mozilla.org/en/DOM/event" rel="no follow"\\\code> Event 对象 ,该属性指向源 DOM 节点。因此,您可以轻松使用 。

var nn = evt.target.nodeName.toLowerCase();
if (nn != "input" && nn != "textarea")
    // do your special handling

http://dev.w3.org/html5/spec/assimation-of- control-and-forms.html#dom-fae-form" rel=“nofollow”_code>form pression ,其中指出元素所有人的形式:

if (! "form" in evt.target)
    // do your special handling




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签