首页 \ 问答 \ jQuery keydown和:没有输入(jQuery keydown and :not with inputs)

jQuery keydown和:没有输入(jQuery keydown and :not with inputs)

我正在使用一个小脚本,当按下箭头键时触发页面上的下一个/上一个链接。 当用户输入我的搜索输入表单时,我试图阻止这种情况发生(也许他们拼错了他们的查询并希望使用箭头键来修复)。

这是我正在使用的:

var $j = jQuery.noConflict();

$j(function(){
    $j('.n').click(function() {
        location.href = $j(this).attr('href')
    });
    $j('.p').click(function(){
        location.href = $j(this).attr('href')
    });
});

$j(':not(input)').keydown(function(event) {
    if(event.keyCode==39) {
        $j('.n').trigger('click')
    }
    if(event.keyCode==37) {
        $j('.p').trigger('click')
    }
});

HTML基本上只是一个带有input字段的form 。 当光标在输入中时,触发仍然会进行。 我不确定我做错了什么。 任何帮助深表感谢!


I am using a small script that triggers the next/previous links on the page when an arrow key is pressed. I am trying to prevent this from happening when a user is typing in my search input form (maybe they spelled their query wrong and want to use the arrow keys to fix).

Here is what I'm working with:

var $j = jQuery.noConflict();

$j(function(){
    $j('.n').click(function() {
        location.href = $j(this).attr('href')
    });
    $j('.p').click(function(){
        location.href = $j(this).attr('href')
    });
});

$j(':not(input)').keydown(function(event) {
    if(event.keyCode==39) {
        $j('.n').trigger('click')
    }
    if(event.keyCode==37) {
        $j('.p').trigger('click')
    }
});

And the HTML is basically just a form with an input field. The trigger still goes even when the cursor is in the input. I'm not sure what I'm doing wrong. Any help is much appreciated!


原文:https://stackoverflow.com/questions/7369208
更新时间:2022-05-16 14:05

最满意答案

看看QShortcut类:

在某些小部件上,在角色前面使用“&”将自动为该角色创建助记符(快捷方式),例如“E&xit”将创建快捷键Alt + X(使用“&&”显示实际的&符号)。 窗口小部件可能会使用给定快捷方式并执行操作。 在X11上,将不显示&符号,并且字符将加下划线。 在Windows上,通常不会显示快捷方式,直到用户按下Alt键,但这是用户可以更改的设置。 在Mac上,默认情况下禁用快捷方式。 调用qt_set_sequence_auto_mnemonic()来启用它们。 但是,由于助记符快捷方式不符合Aqua的指导原则,因此Qt不会显示带下划线的快捷方式字符。


Look at the QShortcut class:

On certain widgets, using '&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut Alt+X (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.

相关问答

更多
  • 所以我想在按钮标题中突出显示一个字母...... 您尚未指定正在使用的vaadin版本。 但最新的vaadin 7( > 7.4 )版本支持Button标题中的HTML。 NativeButton nb = new NativeButton("Edit"); nb.setCaptionAsHtml(true); So I want to highlight one letter in button caption... You have not specified the vaadin ve ...
  • 按下Alt键时,N将自动加下划线。 您将在任何Windows应用程序中看到此行为,因为它是系统范围的设置。 如果您想在不必按Alt的情况下始终获得下划线,请转到控制面板中的轻松访问中心并选中“下划线键盘快捷键和访问键”。 The N will automatically be underlined when the Alt key is pressed. You'll see this behavior in any Windows application as it's a system-wide set ...
  • 我认为你只能在谷歌浏览器中用CSS实现这一点。 例如: 您可以选择占位符的第一个字母 ::-webkit-input-placeholder::first-letter { color: red; text-decoration:underline; } 结果: 使用以下设置时,文本修饰不会呈现:Chrome中的首字母(版本39.0.2171.71)。 所以我们可以实现边界底线的下划线。 ::-webkit-input-placeholder::first-letter { color: r ...
  • 我想你已经看过这个问题了( 在Python / Matplotlib下划线文字 )如果不是这将是我的第一个建议。 其次,我试过并成功地强调了文字。 以下是适用于我的代码片段: import numpy as np import matplotlib.pyplot as plt plt.rc('text', usetex=True) x = np.arange(0, 2*np.pi, 0.1) plt.plot(x, np.sin(x)) plt.text(x[len(x)//2], .5, r'$\und ...
  • 子类UILabel并覆盖drawRect方法,如下所示。 下划线将具有same text color标签same text color和text alignment : - (void)drawRect:(CGRect)rect { if([[self.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) { CGContextRef c ...
  • .single_box a {text-decoration:none;} .single_box a {text-decoration:none;}
  • 看看QShortcut类: 在某些小部件上,在角色前面使用“&”将自动为该角色创建助记符(快捷方式),例如“E&xit”将创建快捷键Alt + X(使用“&&”显示实际的&符号)。 窗口小部件可能会使用给定快捷方式并执行操作。 在X11上,将不显示&符号,并且字符将加下划线。 在Windows上,通常不会显示快捷方式,直到用户按下Alt键,但这是用户可以更改的设置。 在Mac上,默认情况下禁用快捷方式。 调用qt_set_sequence_auto_mnemonic()来启用它们。 但是,由于助记符快捷方式 ...
  • 你可以使用:after伪元素来保存你的下划线: .underlined { position: relative; margin-right: 1rem; } .underlined:after { content: ""; position: absolute; bottom: -10px; left: 0; height: 7px; width: 100%; border: solid 2px #cb1829; border-color: ...
  • CSS文本在应用字母间距时下划线太长? http://jsfiddle.net/isherwood/JWcGh/2 .main-navigation a:after { /* absolute positioning keeps it within h1's relative positioned box, takes it out of the document flow and forces a block-style display */ position: absolute; /* th ...
  • 在您的代码中有3个错误: 您必须首先调用setupUI函数,因为此处创建了按钮,然后将该按钮连接到插槽。 当按钮连接到插槽时,您只需传递插槽名称而不带括号。 将statusbar()更改为statusBar() 。 码: [...] class MyMainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)