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 aninput
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
最满意答案
看看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 ...
-
matplotlib文字下划线(matplotlib text underline)[2024-02-07]
我想你已经看过这个问题了( 在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 ... -
在iphone中的文字下划线(Text Underline in iphone)[2023-08-18]
子类UILabel并覆盖drawRect方法,如下所示。 下划线将具有same text color标签same text color和text alignment : - (void)drawRect:(CGRect)rect { if([[self.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) { CGContextRef c ... -
显示下划线的文本下划线(Text Underline Showing Underline)[2023-02-06]
.single_box a {text-decoration:none;} .single_box a {text-decoration:none;} -
在QT按钮的文字(一个字母)中使用下划线是否可行?(Use underline in the text(one letter) of QT pushbutton is posible?)[2023-10-08]
看看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下划线和字母间距(CSS underline and letter-spacing)[2023-08-09]
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) ...