简体   繁体   中英

How to Auto Focus on next input box with jeasyui

I have a problem setting focus in the next textbox am using the easy UI plugin. I know there is an option do this with MaskedBox

<input class="easyui-maskedbox" mask="(999) 999-9999" style="width:100%"> 

but I want to do this with the easyui-textbox can anyone help me do this functionally.

HTML:

 <div class="otp-textbox">
    <input type="text" class="easyui-textbox" />
    <input type="text" class="easyui-textbox" />
    <input type="text" class="easyui-textbox" />
</div>

Generate the HTML in DOM

<div class="otp-textbox">
        <input type="text" class="easyui-textbox textbox-f" style="display: none;">
        <span class="textbox">
            <input id="_easyui_textbox_input20" type="text" class="textbox-text validatebox-text textbox-prompt"
                autocomplete="off" tabindex="" placeholder="" maxlength="1"
                style="margin: 0px; padding-top: 0px; padding-bottom: 0px; height: 28px; line-height: 28px; width: 182.4px;">
                <input type="hidden" class="textbox-value" value="">
            </span>
        <input type="text" class="easyui-textbox textbox-f" style="display: none;">
        <span class="textbox">
            <input id="_easyui_textbox_input21" type="text" class="textbox-text validatebox-text textbox-prompt"
                autocomplete="off" tabindex="" placeholder="" maxlength="1"
                style="margin: 0px; padding-top: 0px; padding-bottom: 0px; height: 28px; line-height: 28px; width: 182.4px;">
                <input type="hidden" class="textbox-value" value="">
            </span>
        <input type="text" class="easyui-textbox textbox-f" style="display: none;">
            <span class="textbox">
                <input id="_easyui_textbox_input22" type="text" class="textbox-text validatebox-text textbox-prompt"
                autocomplete="off" tabindex="" placeholder="" maxlength="1"
                style="margin: 0px; padding-top: 0px; padding-bottom: 0px; height: 28px; line-height: 28px; width: 182.4px;">
                <input type="hidden" class="textbox-value" value="">
        </span>
    </div>

JS

$(".otp-textbox .textbox").find('input.textbox-text').each(function () {
    $(this).attr('maxlength', 1);
    $(this).on('keyup', function (e) {
        if (this.value.length == this.maxLength) {
            $(this).next().focus();
        }
    });
});

Can you try this:

$(this).nextAll('input').first().focus();

Instad of this:

$(this).next().focus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM