How to move focus on next field when enter is pressed?

后端 未结 7 923
我在风中等你
我在风中等你 2020-12-29 06:02

Can you please tell me how to move focus on to the next field when the enter key is press? I use the dform plugin (which converts JSON to a form).

I Go

7条回答
  •  醉酒成梦
    2020-12-29 06:18

    Try the following JavaScript code that I modified from your fiddle. The default behavior of the select elements will be to expand on the keypress. The plus sign at the beginning of +$(this).attr("tabindex")

    Converts the text attribute value to int.

    $(".ui-dform-text").keypress(function(e) {
        if(e.which == 13) {
    
            // Do something here if the popup is open
            alert($(this).attr("tabindex"));
            var index = +$(this).attr("tabindex") + 1;
    
    
            $("[tabindex='" + index +"']").focus();
        }
    });
    

提交回复
热议问题