开发者

Detecting "enter" keyup event on checkbox

开发者 https://www.devze.com 2023-02-14 04:50 出处:网络
I\'ve got a checkbox called \'beveiligdj\'. It looks like this: <label><input type=\"checkbox\" id=\"beveiligdj\" name=\"beveiligdj\" value=\"j\">Ja</label>

I've got a checkbox called 'beveiligdj'. It looks like this:

<label><input type="checkbox" id="beveiligdj" name="beveiligdj" value="j">Ja</label>

When you select it (by开发者_如何学编程 keyboard) and then press enter, it should go to the #beveiligdn input (also a checkbox) But it does not!

   $('#beveiligdj').keyup(function(event) {

    if(event.keyCode == 13) {
        checked = $('#beveiligdj').is(':checked');

        if(checked) {
            $('#beveiligdn').focus();
        }
    }

   });

It just goes to the following field. How can I fix that?


You can try to use the old trick with the setting of the focus inside of setTimeout:

setTimeout(function(){
    $('#beveiligdn').focus();
},100);

You can even try to use 0 instead if 100.

0

精彩评论

暂无评论...
验证码 换一张
取 消