jQuery - keyup 事件作为函数
我发现了这个使用 keyup 事件的示例:
$(document).keyup(function(e) {
if (e.keyCode == 27) {
//ESC
}
});
这对我有用,但我正在尝试编辑这部分代码的功能,如下所示:
$(function() {
$('a.this_page').live('click', function () {
//simple function - after click on the link will make some action
});
});
我正在尝试将代码的第一部分更新为代码的第二部分 - 我想通过单击链接以及按某个键后执行第二个示例中的操作...但我不确定该怎么做...
任何人都可以吗请帮助我,如何制作? 谢谢。
I found this example of use keyup event:
$(document).keyup(function(e) {
if (e.keyCode == 27) {
//ESC
}
});
This works me, but I am trying to edit this part of code for function, something like this:
$(function() {
$('a.this_page').live('click', function () {
//simple function - after click on the link will make some action
});
});
And I am trying to update the first part of code to the second part of code - I would like to do an action from the second example with click on the link and also after press some key... but I am not sure, how to do..
Could anyone help me, please, how to make it?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
bind()
:JS Fiddle 演示。
显然,上面的演示(我想......)假设您希望在
keyup
和click
事件上发生相同的事情。参考文献:
bind()
。e.type
。You could use
bind()
:JS Fiddle demo.
The above demo, obviously (I suppose...) assumes that you want the same thing(s) to happen on the
keyup
andclick
events.References:
bind()
.e.type
.您必须命名该函数并将其设置为两个事件的事件处理程序,例如:
You will have to name the function and set it as event handler for both events, eg: