Chrome上收音机和复选框的关键事件无法正常工作 [英] Key events on radio and checkboxes in Chrome not working

查看:112
本文介绍了Chrome上收音机和复选框的关键事件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中包含无线电和复选框类型的输入字段。我希望能够触发一个事件,当用户按下一个键,而这些输入字段中的一个焦点。



我的代码是:

 < li class =duplicatable> 
< input type =radioname =avalue =v/>
< / li>

在文档加载中,我应用事件处理:

  $('。duplicatable')。keypress(function(event){
console.log('pressed:'+ event);
}) ;

我也试过:

<$ p $ ('press:'+ event);
} $(document).on('keypress','.duplicatable',function(event){
console.log );

我也试过:

<$ p $


$ >我测试了在Chrome和Firefox中可以使用的点击事件,但是当这是一个关键事件时,Firework可以正常工作,但Chrome并没有做任何事情。



Chrome是否无法处理关键事件在无线电和复选框(或,而不是li元素)?

解决方案

您是否尝试过直接绑定事件输入:

  $('。duplicate input:checked')。click(/*...*/)


I have a page which contains input fields of type radio and checkbox. I want to be able to trigger an event when the user presses a key whilst one of these input fields are focused.

My code is:

<li class="duplicatable">
    <input type="radio" name="a" value="v" />    
</li>

And in document load I apply the event handling:

$('.duplicatable').keypress(function(event) {
    console.log('pressed: ' + event);
});

I have also tried:

$(document).on('keypress', '.duplicatable', function(event) {
    console.log('pressed: ' + event);
});

I have also tried:

$('.duplicatable > li') etc...

I have tested the click event which does work in Chrome and Firefox, but when this is a key event, Firework works, but Chrome does nothing.

Is Chrome not handling key events at all on radio and check boxes (or, rather li elements)?

解决方案

Have you tried bind the event directly on the input:

$('.duplicate input:checked').click(/*...*/)

这篇关于Chrome上收音机和复选框的关键事件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆